For the exact same reason why all modern languages have enumerative types:
because it's better if the interpreter (or compiler) can syntactically
control the range of possible values.
I'm quite a sloppy typist, and I will end up with lots of
{% if status == "eror" %}xyz{% endif %}
that will never get caught by the interpreter.
This, of course, does not happen outside of templates, where the standard
recipes all use class attributes, as in
class Enum( object ):
ERROR; OK = range( 2 )
or module globals, as in
ERROR, OK = range( 2 )
that are used in place of magic numbers, or magic strings.
You can of course write
ERROR, OK = "error", "ok"
but then you'll refer to such values in the code as
if status == ERROR:
and not
if satus == "error":
a typo in the first case is immediately reported by the interpreter, while
in the second case will act like a time bomb in the code.
Is this convincing?
Best,
Massimo
--
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pocoo-libs?hl=en.