enum abuse

Namespace rswhite4 at googlemail.com
Fri Feb 28 11:10:11 PST 2014


On Friday, 28 February 2014 at 18:21:39 UTC, Steve Teale wrote:
> On Friday, 28 February 2014 at 11:47:45 UTC, Vladimir Panteleev 
> wrote:
>
>> A "const" or "immutable" declaration would declare a constant 
>> variable - meaning, unless it is optimized out at a later 
>> point, it will end up in the data segment and have its own 
>> address. An enum declares a manifest constant - it exists only 
>> in the memory of the compiler. Manifest constants make sense 
>> when doing metaprogramming. Constant/immutable declarations 
>> make sense for values that will be used in multiple places by 
>> code at runtime.
>
> I'm with Mike - thanks Vlad, that makes it perfectly clear. I 
> just wonder slightly why a language that prides itself so on 
> its metaprogramming capabilities does not have a keyword that 
> makes it obvious

D has many of those. Would you think, that inout is a wild 
modifier which transfers to const or none-const? Or that 'in' is 
short for 'const scope'? That's because Walter and Andrei won't 
like to add more keywords and reuse old ones from D1 times. It's 
not that obvious but that's D. ;)


More information about the Digitalmars-d-learn mailing list