Why D const is annoying
SomeDude
lovelydear at mailmetrash.com
Wed May 2 00:38:51 PDT 2012
On Wednesday, 2 May 2012 at 06:44:30 UTC, Mehrdad wrote:
> Whether the compiler makes **GUARANTEES** about code is
> _irrelevant_ to whether or not the language uses 'const' to
> improve performance.
>
> You could very well have a language which **enforces**
> const-ness (i.e. doesn't prevent casting it away), but which
> _doesn't_ use it to improve performance.
> Or which does.
>
Yes, pure functional languages do provide this kind of guarantee,
by simply forbidding immutability at the cost of copying objects.
I agree D's solution isn't "pure" as it must allow mutability,
and I suspect it can't be, unless it starts copying objects all
over the place. That means that when you use the immutable
keyword, you *really* mean it and you *must* think that way. If
you want to mutate your object, you have to copy it to another
object. Thats how strings are designed. For me, your example
doesn't prove that the tool is broken, it proves that you don't
know how to use immutability. It's really another paradigm, which
has its uses, in particular in concurrent programming.
More information about the Digitalmars-d
mailing list