Matter of style, and cast()

bearophile bearophileHUGS at lycos.com
Mon Aug 5 06:01:18 PDT 2013


Some small style rules for D user code:

1) All variables and functions arguments should be 
immutable/const (or enum), unless they have to mutate (or there 
is some other problem in Phobos, in the D type system, or in your 
other code).

2) The code should contain as few cast() as possible. [*]

3) Where possible it's better to use foreach() instead of for() 
loops.

4) for/foreach/while loops are not evil, but it's better to use 
map/filter/zip where possible and where performance allows them.

5) Functions/methods should be pure and nothrow where possible.

- - - - - - -

[*] The D type system (and Phobos) should be improved to help 
reduce their frequency. Some of the enhancement requests I have 
written on that:

http://d.puremagic.com/issues/show_bug.cgi?id=10018  (By Lionello 
Lunesu)
http://d.puremagic.com/issues/show_bug.cgi?id=10594
http://d.puremagic.com/issues/show_bug.cgi?id=10615
http://d.puremagic.com/issues/show_bug.cgi?id=10685
http://d.puremagic.com/issues/show_bug.cgi?id=10749
http://d.puremagic.com/issues/show_bug.cgi?id=10751

More not-too-much-hard-to-implement ideas are welcome.

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list