D const design rationale

Lars Ivar Igesund larsivar at igesund.net
Wed Jun 27 09:02:34 PDT 2007


Oskar Linde wrote:

> Apologies for being so harsh (and hyperbolic), but I feel this is (as
> strange as it may sound) a quite important issue.

No reason to apologize, the current implementation is far from perfect, even
ignoring the plethora of keywords involved.

Let me try to list some that I have been able to pick up, even in my
ignorance:

 * constant don't mean read only, so even though const can be considered to
mean constrained, it don't, and should thus not be used to mean read only.
Oskar's suggestion readonly is the best yet. Add to the damage of the new
const that it in 1.0 always mean immutable. Looking to C++/listening to C++
users in this respect may be the worst mistake in D's history yet.
 * invariant as the keyword for immutable/constant would have been ok, if it
hadn't been for the fact that it is used in another context, where empty ()
had to be added to separate from the immutable meaning. The easy fix is of
course to use const to mean immutable/constant, since readonly should be
used to mean read only.
 * const-by-default has been completely ignored/put down, even if _everyone_
giving their opinion in the newsgroup said "give it a try"

Then there are some things that at least appears to be inconsistent:

 * why are D string literals invariant(char)[] whereas C string literals are
invariant(char*) ? This probably ties in with why invariant(char*) and
invariant(char[]) behaves differently in the first place.

I'm sure there are other questions to ask, or that have already been asked.

Walter, I think it's time to pick up your promise again, to have D go
wherever the community wants it to go. This don't currently seem to be
happening. It was mentioned on IRC that D 2.000 don't seem to have got much
praise yet, and as far as I can see, there are good reasons for this. D is
having it's biggest change yet, and the community in general seems to have
more or less qualms with the current implementation. 

-- 
Lars Ivar Igesund
blog at http://larsivi.net
DSource, #d.tango & #D: larsivi
Dancing the Tango



More information about the Digitalmars-d mailing list