On 02.02.2016 15:36, Bambi wrote:
The example snippet ' immutable(int[]) bar() immutable {} ' brings back
bad memories of redundant declarations of the style ' Object object =
new Object(); '. And homonyms in programming languages seem like a bad
idea in general.
"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.