Top 5

Oskar Linde oskar.lindeREM at OVEgmail.com
Sat Oct 11 08:45:09 PDT 2008


Andrei Alexandrescu wrote:
> Oskar Linde wrote:
>> Andrei Alexandrescu wrote:
>>> Don wrote:
>>>> Steven Schveighoffer wrote:
>>>>> "Benji Smith" wrote
>>>>>> And why do we need any special keyword?
>>>> [...] The only reason we need manifest constants is because OPTLINK 
>>>> isn't smart enough.
>>>> (And DMD isn't smart enough to discard unreachable variables from 
>>>> the symbol table).
>>
>>> Exactly so.
>>
>> That and the reason Walter mentioned: "There needs to be a way to 
>> declare a constant of type int." (as opposed to const(int)), but I 
>> disregard that statement as something symptomatic of a broken 
>> const-system.
> 
> That is a random statement to make unless backed up. The problem was:
> 
> auto x = CONSTANT;
> 
> People would expect to initialize x with a particular constant but then 
> be able to use it. But auto for all types means give x whatever type 
> CONSTANT has. If CONSTANT has const as part of its type, that will be 
> transferred into x because that's what auto does, not because const is 
> broken in any way, shape, or form.

D1 has the neat concept of constant storage classes, which means that 
basic values can be constant without carrying a separate type modifier.

Const type modifiers are something that only reference types need (and 
D1 lacks), but the D2 const design has forced such type meta-data to 
spill over on the actual data types. I consider that to be a flaw in the 
const system.

>> I've numerous times been trying to argue against the need for manifest 
>> constants, but it has been about as useful as repeatedly banging your 
>> head against a brick wall. And about as rewarding too.
> 
> Manifest constants do exist. Maybe you mean you want a different naming 
> for them.

I argued against the separation of manifest constants and "regular" 
constants. The distinction is unnecessary and confusing.

>> It is good to finally hear that the sole reason we have them is 
>> laziness. That makes acceptance much easier. :)
> 
> Well priorities are an issue too. Rewriting the linker would be a major 
> effort. Walter would do it if really necessary.

I fully understand that. I just felt I had to write something 
provocative to get a reply. I do consider the reason perfectly valid. :)

-- 
Oskar



More information about the Digitalmars-d mailing list