Hacker News new | past | comments | ask | show | jobs | submit login
Why don’t people use enum in Python? (garlicsim.org)
4 points by cool-RR on June 10, 2011 | hide | past | favorite | 3 comments



Declaring that you've never programmed in Java, then cherry-picking a type from the language and asking why Python doesn't have it, is quite ironic, given the vast differences in typing between the two languages.


I really don't understand your point. I'm happy to learn things from Java and apply them in Python despite the fact that I never programmed Java.

Regarding the differences in typing between Java and Python: Despite of these differences, `flufl.enum` does work in Python, so I don't see how these differences are relevant.


flufl.enum attempts to reject PEP 354, ... [and] defines an alternative syntax and semantics.

PEP 354 was a proposal to add enums to the language, stating:

The properties of an enumeration are useful for defining an immutable, related set of constant values that have a defined sequence but no inherent semantic meaning.

I'm sure someone raised this question while the PEP was being debated: If you are looking for an immutable, related set of (though not immutable or constant) values, you should look no further than the list object.

In fact, most of the PEP could be run through a find and replace, with enum being replaced by lists, or sets, or other types that have attributes from the Sequence abstract base class.

But anyway, that's just a few Python specific things I could think off the top of my head.

My central argument revolves around the differences between Java and Python, and how I've seen enums used. The Java programming language is statically typed, and it is useful to have a basic type that can contain a value, from a set of immutable values. It helps catch any obvious errors, at compile time. For example, using a value which is not part of the enum definition.

Python, being a dynamic language, doesn't have the notion of a compile-time type check.

>I'm happy to learn things from Java and apply them in Python despite the fact that I never programmed Java.

Well, that's a statement that is sure to cause a few eyebrows to be raised.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: