Immutability and other attributes, please review

Jonathan M Davis jmdavisProg at gmx.com
Thu Jun 14 03:06:50 PDT 2012


On Thursday, June 14, 2012 11:51:44 Jacob Carlborg wrote:
> On 2012-06-14 11:19, Roman D. Boiko wrote:
> > I have not much experience in D programming yet, and one of things which
> > I frequently mess up is usage of various attributes, especially
> > immutable and related.
> > 
> > Could anybody make a review my code at
> > https://github.com/roman-d-boiko/functional-data-structures/blob/master/fd
> > s/persistent.d,
> > https://github.com/roman-d-boiko/dct/blob/master/fe/syntax.d, and
> > https://github.com/roman-d-boiko/dct/blob/master/fe/_/syntax.d with
> > respect to usage of attributes (immutable, const, pure, etc.),
> > contracts, and any other issues.
> > 
> > I'm redesigning my previous coding attempts to build D compiler front
> > end, and would like to pay attention to these aspects. Please note that
> > adding DDoc comments has been deferred because I need to learn how to
> > use them.
> 
> Just a note on the style. The convention is to but all attributes on
> front of the return type, except for "const", when "const" is referring
> to that the method is const and not the return type.

That varies considerably from person to person. I don't think that there's 
really any agreed upon order other than the fact that most people agree that 
const should go on the right when it's modifying the function. Personally, I 
put almost everything on the right-hand side (the only exceptions being 
static, @property, and the access modifiers). It is true, however, that a 
number of people put the attributes before the return type. I really wish that 
they wouldn't though.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list