A few questions

Jonathan M Davis jmdavisProg at gmx.com
Fri Jul 27 10:49:02 PDT 2012


On Friday, July 27, 2012 19:34:52 Simen Kjaeraas wrote:
> On Fri, 27 Jul 2012 17:35:19 +0200, Jonathan M Davis <jmdavisProg at gmx.com>
> 
> wrote:
> > Many of us think that
> > 
> > const Foo func() {}
> > 
> > should just become illegal inconsistency or not because of all of this
> > confusion, but Walter doesn't buy into that.
> 
> Like monarch_dodra said, this is also a style favored by some:
> 
> @pure @property const
> int foo() {
>      //...
> }
> 
> Having to write that
> 
> @pure @property
> int foo() const {
>      //...
> }
> 
> at the very least feels weird.
> 
> int foo()
> const @pure @property {
> }
> 
> could work, I guess. But it feels backward.

Personally, I _always_ put the attributes on the right-hand side save for the 
ones which exist in C++ and Java (which is pretty much just the access 
specifiers, static, override, and final), and I think that it's ugly and 
confusing to have them on the left, but that's a matter of personal 
preference. const on the other hand constantly causes issues because - unlike 
the others - it can be applied to the return type as well. And the question 
comes up often enough that I think that it's a real problem and one that 
merits making putting it on the left illegal. At minimum, making it illegal on 
the left without other attributes between it and the return type should be 
illegal IMHO (though that could cause even more confusion depending on the 
error message, since then it might be confusing why you could put it on the 
left but only in some positions). That change isn't going to happen at this 
point, but I think that we'd be better off if it were.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list