Changes before 1.0

Bill Baxter dnewsgroup at billbaxter.com
Sun Dec 3 23:52:12 PST 2006


janderson wrote:
> Bill Baxter wrote:
>> janderson wrote:
>>>> It would be helpful if the following code would work:
>>>>     enum TestEnum {
>>>>         Value1, Value2
>>>>     }
>>>>     writefln("%s", TestEnum.Value2);
>>
>> I agree that I've wanted this kind of feature before too, but I don't 
>> want it at the expense of bloating every single library that contains 
>> enums with lots of string equivalents that will never get used in real 
>> code.  I.e. this kind of thing is really only useful for debug or 
>> prototype code.
>> --bb
> 
> I don't agree on this point (that it would only be used in debug).  As I 
> said, in scripting  (ie game ai ect...) and in plugin libraries (ie 
> maya) its common place to use a string lookup for enums.  The code isn't 
> *much* longer or more bug pron 

Mmmm -- bug pr0n.  *much* longer ... more bug pr0n....  :-)

> to write unless you go the other way and 
> want it to be efficient (ie string->enum is more complex then 
> enum->string).  Still both cases are pretty trivial to write in code.
> 
> I guess the main thing going for it is that users would recognize the 
> pattern much more quickly (ie readability) although it does reduce the 
> chance of offset errors (had one of those just the other day).
> 
> -Joel

Useful for bridging with scripting code. That's a good point.  Python 
has no enums either, so they sometimes get turned into strings when 
going into Python land.

Hey Kirk if you're listening, what does PyD do with enums?

--bb



More information about the Digitalmars-d mailing list