Design of reflective enums

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Mon Feb 19 15:11:49 PST 2007


Michiel wrote:
> Andrei Alexandrescu (See Website For Email) wrote:
> 
>>> Well I think that Ada does it in the core language (but I think that
>>> they are not printable), it is able to define enum as an index array
>>> as you suggest in your second email.
>>> As the more I look at D, the more I find it similar to Ada, it is
>>> perhaps a good idea to make them those enhanced enum in the core
>>> language, and as an improvement to Ada those enum should be printable
>>> (maybe as an option to save memory) .
>> On the contrary, I think it would be great if it were _not_ in the core
>> language, and I'd be happy if a library enum was so good, it would cause
>> deprecation of the built-in one.
> 
> That's a strange thing to hope for. There are advantages to having a
> feature in the core language instead of a library. Several of them are
> summed up on the website. In this case:
> 
> * The syntax will be nice and clean.
> * The compiler knows exactly what you mean and can optimize accordingly.
> 
> Those are not true of library implementations.

These particular advantages don't come forward in the case of enums. 
Core language features also have a lot of disadvantages, such as 
increasing the size of the language's definition, making the feature 
inherently rigid and hard to evolve, and putting the onus on the 
language implementer.

I see how strings can be meaningfully made part of the language, but 
instead of beefing up enums to the behemoth they are in Java, it's much 
more attractive to allowing libraries to do that.


Andrei



More information about the Digitalmars-d mailing list