const/immutable member functions
foobar
foo at bar.com
Mon Jan 24 14:47:39 PST 2011
Don Wrote:
> Steven Schveighoffer wrote:
> > On Mon, 24 Jan 2011 13:36:36 -0500, bearophile
> > <bearophileHUGS at lycos.com> wrote:
> >
> >> There are six, seven or more people that wish to do something about
> >> this situation. TDPL is the D2 reference, but few little changes over
> >> its first edition are acceptable if they improve the D language a little.
> >>
> >> - Trass3r: asks if the code is ambiguous
> >> - Jonathan M Davis: does't like it and puts const/etc on the right
> >> - Simen kjaeraas thinks it's ambiguous though, and should be
> >> disallowed, or at very least, discouraged.
> >> - Jens Mueller: Preferred style is to write const on the right
> >> - Andrej Mitrovic suggests to use @ but says it clutters up source code.
> >> - I agree with Jonathan M Davis.
> >>
> >> What other people think about this situation? Do you want
> >> const/immutable to be required on the right, or do you prefer the
> >> current situation, or do you prefer some other solution?
> >
> > I wouldn't say that I *prefer* the current solution, but the current
> > solution is not so bad that I need it changed.
> >
> > It works fine, despite being confusing. If it wasn't consistent with
> > the rest of the attributes, I'd say it was in need of changes, but it
> > fits within the scheme already outlined.
>
> It's a problem for all of the other attributes as well. I wish it were
> disallowed for all of them.
> Incidentally, putting it afterward always works. Putting it before
> doesn't always work, due to compiler bugs (for example, prefix 'pure'
> doesn't work for inner functions).
This "problem" happens because D belongs to the C-family of languages which puts the return type _before_ the function name.
Languages that don't follow this syntactic convention (some would call it a mistake) have it very consistent and readable:
attribute funcName inputParams -> outputParams { body }
This is the typical functional language design.
Of course I'm not suggesting to apply such a huge change to D but if I were to design a brand new language than I would put the return type at the end.
I feel that putting function attributes at the end increases this IMHO bad design which boils down to a right-to-left programming language.
I'm a native Hebrew speaker and it looks weird to me, so I can't imagine how it could look right to any left-to-right language native speaker...
More information about the Digitalmars-d
mailing list