Changes before 1.0

janderson askme at me.com
Sun Dec 3 23:09:39 PST 2006


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 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



More information about the Digitalmars-d mailing list