any news on const/invariant?

Walter Bright newshound1 at digitalmars.com
Thu Nov 29 02:49:26 PST 2007


Oskar Linde wrote:
> Ok, but it is then unfortunate that having two constants:
> 
> invariant a = 1;
> const     b = 2;
> 
> that typeof(&a) != typeof(&b).

It's not that bad. Consider:
	int a = 1;
	float b = 1;
They're different types, too.

> And regarding C++, it 
> doesn't seem to me like const was originally intended to mean "read only 
> view". I'd guess the logical evolution was 1. const as a storage class 
> to replace #defines -> 2. pointers to const -> 3. contract const (I 
> promise I wont change this). Should D really copy only the most 
> unintended part of what const is from C++ and change the most intended one?

Is it really unintended? But even so, if you have invariant, you must 
have const too, since everything is implicitly convertible to const, and 
*that* is definitely intended in C++.


> I'm only saying that I think there is another set of keywords that have 
> a much higher match between the dictionary meaning of the words and 
> their semantic meaning in D.

I don't believe there is (and we looked!), and readonly isn't it. To me, 
readonly means ROM (burned in to read only memory chips), not read only 
view. I've even seen 'readonly' used in some languages to literally mean 
"this stuff goes into ROM".



More information about the Digitalmars-d mailing list