Interested in D, spec confuses me.

anonymous via Digitalmars-d digitalmars-d at puremagic.com
Tue Feb 2 12:13:41 PST 2016


On 02.02.2016 20:50, Bambi wrote:
> Making the return value immutable is a very different thing from making
> every value of the object immutable to the method alone.

Sure it's a different thing, but the meaning of "immutable" is the same.

By the way, it's not that the object's fields are made immutable for the 
method, but the method can only be called on immutable objects.

> These are
> different meanings. It reads like a redundancy but has different
> meanings. This isn't good in my eyes.

I don't see how it reads like a redundancy. Surely, you don't expect a 
redundancy in this:

void f(immutable int[] a, immutable int[] b);

The other signature is no different. Two occurrences of "immutable", 
applying to two different things.

I agree that it can be unclear to newbies what exactly is immutable when 
a method is marked immutable, but the meaning of the keyword is the same 
as elsewhere. Using another word there would be more confusing.


More information about the Digitalmars-d mailing list