www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Idiomatic D?

reply "Tofu Ninja" <emmons0 purdue.edu> writes:
I hear it thrown around a lot but what does it actually mean? 
What does the ideal D code look like? What kind of things should 
some one think about if they are trying to do idiomatic D?
Jan 30 2014
next sibling parent reply "Dicebot" <public dicebot.lv> writes:
On Thursday, 30 January 2014 at 20:05:11 UTC, Tofu Ninja wrote:
 I hear it thrown around a lot but what does it actually mean? 
 What does the ideal D code look like? What kind of things 
 should some one think about if they are trying to do idiomatic 
 D?
There is no "official" idiomatic style like, for example, in python. When I speak about idiomatic D I usually think about style Phobos is written in (omitting legacy modules) as it is the code that gets most attention from most experienced D developers.
Jan 30 2014
parent reply "Tofu Ninja" <emmons0 purdue.edu> writes:
On Thursday, 30 January 2014 at 20:10:01 UTC, Dicebot wrote:
 On Thursday, 30 January 2014 at 20:05:11 UTC, Tofu Ninja wrote:
 I hear it thrown around a lot but what does it actually mean? 
 What does the ideal D code look like? What kind of things 
 should some one think about if they are trying to do idiomatic 
 D?
There is no "official" idiomatic style like, for example, in python. When I speak about idiomatic D I usually think about style Phobos is written in (omitting legacy modules) as it is the code that gets most attention from most experienced D developers.
Got any tips?
Jan 30 2014
next sibling parent reply "Meta" <jared771 gmail.com> writes:
On Thursday, 30 January 2014 at 22:40:24 UTC, Tofu Ninja wrote:
 On Thursday, 30 January 2014 at 20:10:01 UTC, Dicebot wrote:
 On Thursday, 30 January 2014 at 20:05:11 UTC, Tofu Ninja wrote:
 I hear it thrown around a lot but what does it actually mean? 
 What does the ideal D code look like? What kind of things 
 should some one think about if they are trying to do 
 idiomatic D?
There is no "official" idiomatic style like, for example, in python. When I speak about idiomatic D I usually think about style Phobos is written in (omitting legacy modules) as it is the code that gets most attention from most experienced D developers.
Got any tips?
Ranges, templates and structs.
Jan 30 2014
parent reply "Stanislav Blinov" <stanislav.blinov gmail.com> writes:
On Friday, 31 January 2014 at 00:08:02 UTC, Meta wrote:
 On Thursday, 30 January 2014 at 22:40:24 UTC, Tofu Ninja wrote:
 Got any tips?
Ranges, templates and structs.
~= CTFE ~ UFCS
Jan 30 2014
parent reply "Meta" <jared771 gmail.com> writes:
On Friday, 31 January 2014 at 00:09:34 UTC, Stanislav Blinov 
wrote:
 On Friday, 31 January 2014 at 00:08:02 UTC, Meta wrote:
 On Thursday, 30 January 2014 at 22:40:24 UTC, Tofu Ninja wrote:
 Got any tips?
Ranges, templates and structs.
~= CTFE ~ UFCS
~= std.algorithm ~ std.range
Jan 30 2014
parent reply "Stanislav Blinov" <stanislav.blinov gmail.com> writes:
On Friday, 31 January 2014 at 00:13:02 UTC, Meta wrote:

 Ranges, templates and structs.
~= CTFE ~ UFCS
~= std.algorithm ~ std.range
~= immutable ~ (isProperlyImplemented!shared ? shared : repeatedlyAskAndreiWhatsGoingOnWith!shared
Jan 30 2014
next sibling parent "Meta" <jared771 gmail.com> writes:
On Friday, 31 January 2014 at 00:17:47 UTC, Stanislav Blinov 
wrote:
 On Friday, 31 January 2014 at 00:13:02 UTC, Meta wrote:

 Ranges, templates and structs.
~= CTFE ~ UFCS
~= std.algorithm ~ std.range
~= immutable ~ (isProperlyImplemented!shared ? shared : repeatedlyAskAndreiWhatsGoingOnWith!shared
Repeat these steps until you have a beautiful, elegant solution, or ten pages of compiler errors because a template constraint failed somewhere down the line.
Jan 30 2014
prev sibling parent reply Matt Soucy <msoucy csh.rit.edu> writes:
On 01/30/2014 07:17 PM, Stanislav Blinov wrote:
 On Friday, 31 January 2014 at 00:13:02 UTC, Meta wrote:

 Ranges, templates and structs.
~= CTFE ~ UFCS
~= std.algorithm ~ std.range
~= immutable ~ (isProperlyImplemented!shared ? shared : repeatedlyAskAndreiWhatsGoingOnWith!shared
); // Sorry but that was going to cause a slight error. -- Matt Soucy http://msoucy.me/
Jan 30 2014
parent "Stanislav Blinov" <stanislav.blinov gmail.com> writes:
On Friday, 31 January 2014 at 04:53:48 UTC, Matt Soucy wrote:

 Ranges, templates and structs.
~= CTFE ~ UFCS
~= std.algorithm ~ std.range
~= immutable ~ (isProperlyImplemented!shared ? shared : repeatedlyAskAndreiWhatsGoingOnWith!shared
); // Sorry but that was going to cause a slight error.
I knew I forgot something...
Jan 30 2014
prev sibling next sibling parent "qznc" <qznc web.de> writes:
On Thursday, 30 January 2014 at 22:40:24 UTC, Tofu Ninja wrote:
 On Thursday, 30 January 2014 at 20:10:01 UTC, Dicebot wrote:
 On Thursday, 30 January 2014 at 20:05:11 UTC, Tofu Ninja wrote:
 I hear it thrown around a lot but what does it actually mean? 
 What does the ideal D code look like? What kind of things 
 should some one think about if they are trying to do 
 idiomatic D?
There is no "official" idiomatic style like, for example, in python. When I speak about idiomatic D I usually think about style Phobos is written in (omitting legacy modules) as it is the code that gets most attention from most experienced D developers.
Got any tips?
http://qznc.github.io/d-tut/idiomatic.html
Jan 31 2014
prev sibling parent "Dicebot" <public dicebot.lv> writes:
On Thursday, 30 January 2014 at 22:40:24 UTC, Tofu Ninja wrote:
 There is no "official" idiomatic style like, for example, in 
 python. When I speak about idiomatic D I usually think about 
 style Phobos is written in (omitting legacy modules) as it is 
 the code that gets most attention from most experienced D 
 developers.
Got any tips?
I'd say single most important thing is designing your API's to be range-based and making sure they work nicely with std.algorithm Preferring simple template + procedural/functional solutions over complicated object hierarchies. Treat module as your basic design and incapsulation unit, not class. Don't rely on specific types, prefer generic implmentations. Verify your all your assumptions with constraints and/or static asserts. Use DDOC + documented unittest feature. It rocks.
Jan 31 2014
prev sibling parent "Kelet" <kelethunter gmail.com> writes:
On Thursday, 30 January 2014 at 20:05:11 UTC, Tofu Ninja wrote:
 I hear it thrown around a lot but what does it actually mean? 
 What does the ideal D code look like? What kind of things 
 should some one think about if they are trying to do idiomatic 
 D?
Here is one of the few previous threads on the topic: http://forum.dlang.org/thread/awutlttzvqaawkrjnfqe forum.dlang.org
Jan 30 2014