Enumeration idioms: Values from different enumerations
Peter Hansen
peter at engcorp.com
Thu Dec 15 23:53:36 EST 2005
Ben Finney wrote:
> These are valid concerns. I can't see how to reconcile these against
> the desire for values from different enums to fail comparison.
>
> Am I alone in my tri-state view of enumeration value comparisons? Can
> anyone else defend why values from different enumerations should not
> compare?
While I'm largely a disinterested bystander, it occurs to me that if you
look at the reasons behind wanting enumerations in the first place, you
might find a good reason to defend this view.
For example, if enumerations are intended to reduce the likelihood of
certain types of errors (where the use of typical XXXX=3 "constants"
might be more prone to errors), then perhaps this suggests that passing
errors silently is bad. That is, trying to compare enumerations that
should not be compared *is* an error (raising an exception) *because*
the whole point of enumerations is to avoid errors in such cases.
Or perhaps I'm off the mark as to why people want enumerations. Is it
just a cosmetic consideration? (Yes, I've used and appreciated them
extensively in C and might even pick up Enum for my Python code... I'm
just sort of playing devil's advocate here.)
-Peter
More information about the Python-list
mailing list