Interested in D, spec confuses me.

Bambi via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 2 11:50:57 PST 2016


On Tuesday, 2 February 2016 at 15:48:02 UTC, anonymous wrote:
> "immutable" is not a homonym here. It means the same thing 
> ("cannot ever change"). And it's not redundant either, as the 
> two instances apply to different targets. It's clear what the 
> first "immutable" ties to: It qualifies the return type. The 
> second one is less clear: It qualifies the type of the object, 
> meaning the method can only be called on an immutable object.
>
> Leaving either of them out changes the meaning of the signature:
> `int[] bar() immutable {}` - Return type is mutable now.
> `immutable(int[]) bar() {}` - Object type is mutable now. I.e., 
> this method can be called on a mutable object, and it cannot be 
> called on an immutable object.

Making the return value immutable is a very different thing from 
making every value of the object immutable to the method alone. 
These are different meanings. It reads like a redundancy but has 
different meanings. This isn't good in my eyes.

Also it's not so much an issue of clarification - well, the 
extern one is, I genuinely didn't understand what the 
documentation meant - but it is an issue of the design choices 
not making much sense to me. These just stand out to me as 
unnecessarily confusing and obscure in an otherwise nice and 
clear language.


More information about the Digitalmars-d mailing list