On Mon, 18 Jan 2010 15:35:17 -0500, dsimcha <[email protected]> wrote:

== Quote from Walter Bright ([email protected])'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.

For pure value types (including structs with only pure value types in them), no there is no difference. That is why such value types are implicitly convertable to/from mutable, const and immutable because you always make a complete copy on assignment.

-Steve

Reply via email to