Const sucks

eao197 eao197 at intervale.ru
Tue Sep 11 01:41:06 PDT 2007


On Tue, 11 Sep 2007 04:50:32 +0400, Miles <_______ at _______.____> wrote:

> Walter Bright wrote:
>> Const, final, invariant, head const, tail const, it's grown into a
>> monster. It tries to cover all the bases, but in doing so is simply not
>> understandable.
>
> I was going to say that, that D's const sucks, many months ago, but
> didn't because I was afraid being regarded as a troll.
>
> Its not that I like const-less languages like Java (in fact, I hate
> them), but I think that C++'s const, with all its problems, was the
> right answer (for that time). It fixes the problem without putting much
> burden onto the programmer.
>
> D's const puts way too much burden onto the programmer, and gives very
> little back. Too many different combinations of const, final, invariant,
> pointers and references (and the fact that in D you don't immediately
> know if a type "T" is a reference of a value, specially while writing
> templates, adds to this confusion) with confusing semantics when
> combined (with a few special cases and lack of orthogonality).
>
> When the new const was being designed, I told in this list: "Don't try
> to fix what ain't broken". What I meant was: Don't try to do a new const
> just because you want a better const than C++s. Many people dislike C++s
> const, but are unable to point exactly why it is wrong. Most people
> doesn't even understand C++'s const, and try to get more from it than it
> was actually intended to provide (that is the whole point behind the new
> D's invariant).
>
> Sometimes people give use-cases to exemplify (STL's need for a
> difference between iterator<> and const_iterator<> is the first thing
> that comes to my mind), but then you ask what a language could provide
> to fix this, they don't know. This is where you should aim first you  
> laser.
>
> When I first saw D, I was amazed with the possibilities. Now I'm
> somewhat scared. Perhaps one of the things that are scaring me is just
> like you said: there is a (at least one) monster in the language.

I'm totaly agree with all you have said.

-- 
Regards,
Yauheni Akhotnikau



More information about the Digitalmars-d mailing list