Extended Type Design.

Don Clugston dac at nospam.com.au
Thu Mar 22 00:46:53 PDT 2007


Bill Baxter wrote:
> Don Clugston wrote:
> 
>> The natural association is "const" == "never changes, under any 
>> circumstances". "readonly" == "don't touch".
>> Even for read-only memory, if you've ever used an EPROM burner, or 
>> flashed firmware, you know that someone can write to it. I've changed 
>> readonly memory, I've never changed a constant.
>> The concept of 'read-only' access is pretty widely understood.
> 
> I dunno about that.  Yes if you're talking about physical constants or 
> constants like Pi, they never ever change.  But 'constant' is also used 
> frequently in mathematics to mean something that's simply "not variable 
> in the current context".  Like when doing partial differentiation with 
> respect to y, all variables besides y are treated as constants.

I discussed that already. The proposed 'const' is variable in the 
current context, since (for example) another thread can change it.

If you read a value described as 'const', then read it again later, it 
is not safe to assume that it has not changed. Therefore, it is not 
constant in any meaningful sense.


> Also your definition of constant (i.e. something like Pi which 
> absolutely cannot change) seems to be a more a replacement for the 
> proposed 'final' as in 'final Pi = 3.14;' than for a reference whose 
> referent cannot change.

True. I just can't see much use for 'const' as a keyword.

> So personally I'm of the opinion we should pick two words that make at 
> least a modicum of sense in English, forget about what they might mean 
> in C++ or Java or whatever, make sure the common one is short, easy to 
> type, and easy on the eyes, and just go with it.
> 
> --bb



More information about the Digitalmars-d mailing list