const

Walter Bright newshound1 at digitalmars.com
Fri Mar 28 11:20:00 PDT 2008


Michel Fortin wrote:
> But const in D 1.0 and D 2.0 doesn't mean the same thing does it?

Right.

> I 
> think using readonly for what is const in D 2.0 and const for what is 
> invariant makes more sense... although just like you I don't like much 
> the name "readonly" for that meaning: it looks too much like a synonym.

As I mentioned to Sean, "readonly" has a long history of meaning "nobody 
can write to it." We have ROMs (Read Only Memory) and virtual memory 
that has "Read Only" settings, etc. Redefining readonly this way is 
going to satisfy half the people, and confuse the hell out of everyone else.

The thing about "const" is that the major language that uses it, C++, 
uses it most of the time with the meaning "read only view, but others 
can write to it." The other thing about "const" is that it gets written 
a lot, and (at least in C++) it tends to consume a lot of horizontal 
space. Using a longer keyword would be problematic.

> Ever thought of "shut", "guarded", "shielded", "occluded", or anything 
> else conceptualizing some kind of barrier instead of redefining the 
> meaning of const and overloading the invariant keyword with a second 
> meaning? Or maybe words more like "watched", "witnessed", "espied" -- or 
> maybe just "espy", I like that one -- meaning you can only look at the 
> thing. All these words have no constancy connotation and I think they'd 
> be much better for grasping the D concept of constancy.

We can (and essentially did) debate this forever. The bottom line is, 
it's just a word, and at some level it becomes the color of the bicycle 
shed problem.



More information about the Digitalmars-d mailing list