Immutability by default [was: Re: Tidy auto [Was: Re: @disable]]

dsimcha dsimcha at yahoo.com
Mon Jan 18 12:35:17 PST 2010


== Quote from Walter Bright (newshound1 at digitalmars.com)'s article
> Leandro Lucarella wrote:
> > Do you remember when people asked for default immutability? I do :)
> Yes, but it would break every other line of code already written in D.
> > I like the idea of making x := y an alias for immutable x = y (or even
> > enum x = y). That would make this style much more attractive without
> > breaking backward compatibility as immutable-by-default would do.
> Actually,
>      const x = y;
> is better than immutable, because if y is a T*, it cannot be implicitly
> converted to immutable, while it can be implicitly converted to const.

Refresh my memory, is there any difference whatsoever between const and immutable
for pure value types (int, float, char, etc.), including in terms of the compiler
optimizations they allow?  As far as I can tell, the difference only comes into
existence when there's indirection involved.



More information about the Digitalmars-d mailing list