Does D have too many features?

Timon Gehr timon.gehr at gmx.ch
Sun Apr 29 04:35:49 PDT 2012


On 04/29/2012 08:35 AM, Nick Sabalausky wrote:
> "Timon Gehr"<timon.gehr at gmx.ch>  wrote in message
> news:jnhpvv$ih4$1 at digitalmars.com...
>> On 04/28/2012 11:04 PM, Dmitry Olshansky wrote:
>>>
>>> But how about:
>>> alias thing = runSomeCtfe();
>>>
>>
>> That would work in certain cases, where the initializer is not a single
>> symbol. But then, I kinda like the way 'enum' is generalized in D:
>>
>> enum Foo{
>>      member1,
>>      member2,
>>      member3,
>> }
>>
>> =>  (allow non-integral enumerations)
>>
>> enum Foo{
>>      member1 = "1",
>>      member2 = "2",
>>      member3 = "3",
>> }
>>
>
> Those are good. They are essentially enumerations.
>
>> =>  (anonymous enums)
>>
>> enum{
>>      member1 = "1",
>>      member2 = "2",
>>      member3 = "3",
>> }
>>
>
> I don't think "anonymous enum" makes any sense at all. It's *not* an
> enumeration by any stretch of the term,

enum{
     member1,
     member2,
     member3,
}

static assert(member1+1==member2 && member2+1==member3);


> it's just a series of manifest
> constants. The fact that they're grouped doesn't even have any semantic
> consequence, as far as I'm aware.

The only differences are that they don't occupy their own namespace and 
they don't define their own type. But non-anonymous enums are _just a 
bunch of manifest constants_ as well! Therefore there are ways in which 
the generalisation makes sense.


>
>> =>  (a single member is okay)
>>
>> enum{
>>      member1 = "1",
>> }
>>
>> =>  (syntactic sugar)
>>
>> enum member1 = "1";
>>
>
> Just simpler examples of the above, which isn't any form of enumeration at
> all.
>

'enum' declares manifest constants whether or not it is anonymous. Afaik 
go uses 'const' for enumerations and manifest constants. 'const' means a 
different thing in D. (arguably, 'readonly' would be a better fit) I 
don't think that the exact keywords matter a huge deal here.


More information about the Digitalmars-d mailing list