D const design rationale

Derek Parnell derek at psych.ward
Sat Jun 23 16:34:52 PDT 2007


On Sat, 23 Jun 2007 18:34:59 +0100, Bruno Medeiros wrote:

> Reiner Pope wrote:
>> 
>> I also think that the idea of a "compile time constant" is distinct from 
>> invariant-as-type-constructor. For the purposes of clarity, I think it 
>> would ideally be better to make this distinction clear, and give this 
>> storage class a different name (sorry about Yet Another Keyword). I 
>> think 'define' could make sense:
>> 
>>     define PI = 3.14;
>>     define LanguageName = "D Programming Language";
>> 
>> This also emphasises the similarity in meaning to #define.
>> 
>> Of course, typeof(LanguageName) == invariant(char[])
>> 
>> ---
>> 
> 
> I agree. I don't like this overloading of concepts very much, such that 
> 'invariant' is used both for compile time values, and invariant data. 
> It's quite similiar to 'const' keyword in D 1.0, where it was used both 
> for compile time values, and final values.
> As for an actual alternative, maybe instead of 'define' we could simply 
> use alias:
> Either:
>    alias PI = 3.14;
> or
>    alias 3.14 PI;
> In any case, using 'alias' that way is actually pretty consistent with 
> the current meaning of 'alias'.

I like both 'define' and 'alias' for this idea. 'alias' is not being
overloaded because the concept behind it is retained.

-- 
Derek Parnell
Melbourne, Australia
"Justice for David Hicks!"
skype: derek.j.parnell



More information about the Digitalmars-d mailing list