const property don't wont return const reference to value

Jonathan M Davis jmdavisProg at gmx.com
Mon Dec 24 07:51:12 PST 2012


On Monday, December 24, 2012 14:32:55 monarch_dodra wrote:
> "ref" is a function qualifier, not a type qualifier, so you could
> even write it as:
> "const(ReturnType) foo() const ref;"
> 
> So technically, it is symetric.

I'm pretty sure that ref is nonsensical in that example. What would ref on a 
function even mean? It could be used on a function pointer, but then you'd 
have to have the function keyword in there. It makes no sense on a function 
prototype like you have there. If that compiles, it's because dmd allows you 
to put all kinds of modifiers on symbols where the modifier has no effect and 
arguably shouldn't be legal.

> I for one don't think this is a huge problem. There is *some*
> confusion for those comming from C++, but they (we) have to learn
> D is not C++. Besides, I like the liberty of putting all
> qualifiers on the line before the types, including const.
> 
> If anything "const" *itself* is VERY confusing for new commers.
> WAY more than the syntax used to qualify a function with it.

You're likely to be told to move the const to the right if one of us notices 
it on the left in a pull request. I believe that quite a few of us consider it 
to be bad practice to put it on the left.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list