It's worse than I thought

Craig Black cblack at ara.com
Fri Nov 30 09:14:28 PST 2007


"Janice Caron" <caron800 at googlemail.com> wrote in message 
news:mailman.199.1196440211.2338.digitalmars-d at puremagic.com...
> On Nov 30, 2007 3:48 PM,  <gide at nwawudu.com> wrote:
>> I was under the (wrong) impression that
>> 'const(C)' and 'const C'  were synonymous.
>
>
> Some time ago, Walter started a thread called something like "const
> sucks", in which he agreed that D2.007 const was a mess, and promised
> to go away and rethink it. He has indeed done that - however, the only
> change I can observe is that "head const" has been ditched, along with
> the keyword "final". Everything else that was bad about const is still
> there.
>
> I find this distressing, because I /love/ what Walter is trying to do.
> D-const could be way, way, w-a-y, better than C++ const. I love that
> const is transitive. I'm prepared to live without "logical const" and
> see what happens. I love the fact that the language distinguishes
> between const and invariant, where it makes sense to do that. I love
> that "const(int***)***" is so much more concise than C++'s
> corresponding "int const*const*const*const***". All of this is GREAT!
>
> But what I hate about it is the confusion between (1) const as a
> type-constructor, (2) const as a storage class for variables, (3)
> const as a function parameter storage class, and (4) const as a
> storage class for member functions. (And ditto for invariant). I
> further hate that const/invariant don't apply to declared symbols
> (sometimes). Huh!?
>
> So here are my suggestions for clearing up the mess. They are very
> simple, clean, and elegant:
>
>
> (1) ditch "const as a storage class" altogther. Keep "const as a
> type-constructor". Stick rigidly to the principle that "const(...)"
> means "the stuff in the brackets is const", and nothing else.
>
> (2) allow "const T", where T is a type, to be syntactic sugar for
> "const(T)". But it's still just a type constructor.
>
> (3) use the syntax "const(this)" for const member functions. Make
> "const(this)" an attribute. Ideally, extend the principle to
> "const(anyIdentifier)", but just "const(this)" will do for now.

I like the const(this) idea.  Very explicit.

> (4) let "const(C)&" be the syntax for making mutable references to
> const classes.

I don't think adding an amphersand makes it any more understandable.

> (5) let "const x = y;" be syntactic sugar for "const(typeof(y)) x = y;"

Sure.  We can't already do this?

> And the same for invariant.
>
>
> ...and that's it! 





More information about the Digitalmars-d mailing list