Const sucks

Bill Baxter dnewsgroup at billbaxter.com
Tue Sep 11 01:37:53 PDT 2007


Janice Caron wrote:
> On 9/11/07, *Janice Caron* <caron800 at googlemail.com 
> <mailto:caron800 at googlemail.com>> wrote:
> 
>     It's simple, but - I would argue - the wrong choice. A better choice
>     (in my humble opinion) would be
> 
>     const = constant
>     readonly = read-only
> 
>     If it's not too late to change the keywords, that, to me, would be
>     the way to go.
> 
> 
> 
> By which I mean, if it's at all feasable to consider ditching the 
> keyword "invariant" altogether, and introducing a new keyword 
> "readonly", then let's do it. "readonly" should indicate a read-only 
> view of data which someone else might modify, and "const" should imply 
> that no-one can modify it ever, no way, nohow.
> 
> I'm not quite sure why no one before now has suggested using "readonly" 
> to mean read-only and "const" to mean constant, but seems kind of a 
> no-brainer to me. You know - calling a thing what it is, instead of 
> something it's not. I know I'd be dead confused if int meant float, for 
> example.

It has been suggested before several times.  The problem is there's 
disagreement over what it should mean.  To some it is obvious that 
"readonly" should mean permanently unwriteable, just like "read only 
memory" is unwriteable.  To others it is equally obvious that it should 
mean a read-only view of data that is writeable through some other means.

--bb



More information about the Digitalmars-d mailing list