any news on const/invariant?

Walter Bright newshound1 at digitalmars.com
Wed Nov 28 17:48:02 PST 2007


Oskar Linde wrote:
> Walter Bright wrote:
> 
>> Because those alternatives all look terrible. And frankly, how could 
>> anyone be confused about what:
>>     const x = 3;
>> means? I can't understand throwing that out to improve clarity?
> 
> Honestly, I am confused about what that means. If I define an integer 
> constant x, don't I want a pointer to that constant to be 
> invariant(int)*? Doesn't that mean that constants should rather be 
> defined as:
> 
> invariant x = 3;
> 
> Or am I wrong? What am I missing here?

For a basic type, the meaning of const and invariant overlap. The 
difference between them is when you have pointers or other references. 
For simple integers, you can use const or invariant.

> I am to tired right now to reiterate my full thoughts on the keywords 
> (and I am sure you are all very thankful for that :) ), but it still 
> feels like the keywords are reversed:
> 
> invariant === constant
>     const === read only

We went around this for a while. There is no word that unambiguously 
means "read only view" while another word meaning unambiguously "will 
never change". So, since C++ uses const to mean "read only view", it 
seemed best to leave that as it was.

readonly, constant, invariant, immutable, are all synonyms.



More information about the Digitalmars-d mailing list