On 14 February 2013 05:19, Barry Warsaw
On Feb 13, 2013, at 08:19 AM, Tim Delaney wrote:
I'm of the opinion that the most fundamental property of an enum is that it can generate its values automatically. Everything else is a nice-to-have, but without that property it's not much use as an enum.
See, I don't care about that much because I define an enum once, but I *use* it hundreds of times. Thus a little more verbosity/explicitness at definition time is a one-time cost, and a very low one at that. It might not seems that way when you're writing them in so many mailing list replies though ;).
My main concern regarding this is ensuring that: 1. Values don't get repeated. 2. Values don't get skipped (unless explicitly skipped); #1 obviously is the most important property, but in practice I find #2 to be very important as well. Whilst it's more verbose, the ... syntax isn't bad, and I've added support to it to my enum to play with. Currently my enum implementation includes the kitchen sink, but I'm looking to do some renovations soon.
In real code, having a really good str and repr, along with good semantics makes them much more useful for debugging, and very pleasant to use.
Absolutely. But it's not just that either. If you can convert from the string name to the enum, it makes the enum suitable as a transport mechanism. Each end can have different values for the enum in practice so long as the names don't change - it can make things much more robust across versions. Tim Delaney