Extended Type Design ~ don't forget about enum

kris foo at bar.com
Tue Mar 20 10:47:15 PDT 2007


Andrei Alexandrescu (See Website For Email) wrote:
> kris wrote:
[snip]
>> Was somewhat hoping invariant would be used in place of what has now 
>> taken shape as "const", and "constant" would be used in place of where 
>> "invariant" has landed. Then there would be no "const" to confuse 
>> anyone. Almost seems as though shortening the name by a couple of 
>> bytes is actually more important than the meaning of the words in use?
> 
> 
> I think the 5 letters to 9 letters a difference, especially when 
> repeated many times. And again: invariant and const are synonims. 
> Merriam-Webster lists "constant" as the first meaning of "invariant":
> 
> http://m-w.com/dictionary/invariant

Yeah, I know. Except there's three flies in the ointment:

1) you've already suggested "const" won't get used all that much (or can 
be implied/inferred instead).

2) Then there's the question of whether "constant" is a more appropriate 
term for what "invariant" is slated to do.

3) Additionally, it may well be better to dump "const" altogether simply 
to alleviate potential confusion.

It's hardly a life or death scenario, yet the choices being made really 
do appear to be slanted towards "something" that just doesn't seem 
entirely sensible


>> I'm not sure about "breaking all existing D code" ... there would seem 
>> to be very little use of "const" at this time, because the current 
>> semantics are really kinda worthless; e.g. one should probably use 
>> enum for most things 'constant', except you can't have "enum : char[]" 
>> making enum notably less useful than it could otherwise be.
>>
>> Where does enum fit in this picture anyway? Can it recover some duty 
>> from "const" and/or "final" in a logical and consistent manner?
> 
> 
> If I had my way, I'd make the language powerful enough to express 
> enumerated types in stdlib, then I'd deprecate the built-in one.

Would be good to make the type system more flexible and extensible, but 
that's getting away from the point: enum represents 'constant' values, 
so presumably has some bearing upon this discussion?



More information about the Digitalmars-d mailing list