3 ms·
What purpose would Enums serve in a dynamically-typed language?
by yen223 14y ago
What purpose would Enums serve in a dynamically-typed language?
- oellegaard 14y agoEven though dynamically typed, it still have the concept of types. There are good examples on how it works in the PEP.
- jerf 14y agoAnd more the the point, Python is strongly typed in the sense that it has very few automatic conversions between types, in contrast to, say, Perl. As the PEP says, this means that you can't accidentally compare an enum value of one type to an enum value of another without a runtime error occurring, instead of an infuriatingly subtle bug. Python may defer its type checking to run time, but it still has it.
- eliben 14y agoRead the PEP motivation :-) It's still useful to have mnemonic names for special values, with nice string representations and some guarantees on what is equal to what.