On Tue, Sep 27, 2011 at 9:57 AM, Gor Gyolchanyan <span dir="ltr"><<a href="mailto:gor.f.gyolchanyan@gmail.com">gor.f.gyolchanyan@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
After using D for quite a while I've developed some minor design<br>
patterns and code style suggestions, that could be useful.<br>
I wanted to post them somewhere on the internet, but then i thought,<br>
that the best place to put D-related useful information is on the<br>
official webpage itself.<br>
So i ask you guys, do you think it would be a good idea to create a<br>
section on <a href="http://www.d-programming.language.com/" target="_blank">http://www.d-programming.language.com/</a>, devoted to design<br>
patterns, guidelines, best practice advices and similar stuff?<br>
If so, I'd like you to post your experience to that section, so there<br>
will be a big and reliable source of help on how to program on D on<br>
it's official site.<br>
<br>
Example of a coding pattern:<br>
<br>
If you have a class or struct, that has a lookup function by string<br>
identifier, consider using opDispatch to add a very convenient syntax<br>
sugar to your class or struct. And if the lookup term can be run-time<br>
defined, make an opIndex for that, write the implementation in opIndex<br>
and forward the call from opDispatch to opIndex, possibly doing<br>
caching, knowing, that the search term is compile-time defined.<br>
<br>
Cheers,<br>
<font color="#888888">Gor.<br>
</font></blockquote></div><br><div>I'd love some guidelines and tips for writing idiomatic D code like you've written above.  Whenever I'm learning a new language (as I am doing currently with D) I'm often concerned I'm not doing things the "proper" way and instead just using the techniques I know from other languages.  Python, for example, has Code Like a Pythonista [1] which I found very helpful for learning to do things the Python way.  Of course, it may be tricky getting people to agree on what "idiomatic D" is.</div>
<div><br></div><div>Similarly, a "cookbook" (snippets for common problems) is also often very useful to both beginners and even experienced users of a language. Stack Overflow [2] may fill this role better than a custom rolled solution though since it's easier to keep solutions up to date. The R language community held a little event [3] where they filled Stack Overflow up with the top 100 common questions and answers.  I think this is something the D community may want to consider (especially given the very high quality answers to questions about D that have been posted to Stack Overflow in the past).</div>
<div><br></div><div>[1] <a href="http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html">http://python.net/~goodger/projects/pycon/2007/idiomatic/handout.html</a></div><div>[2] <a href="http://www.stackoverflow.com">http://www.stackoverflow.com</a></div>
<div>[3] <a href="http://blog.stackoverflow.com/2009/07/stack-overflow-flash-mobs/">http://blog.stackoverflow.com/2009/07/stack-overflow-flash-mobs/</a></div>