Enumeration Types (when required)

Mike Brenner mikeb at mitre.org
Wed Jun 21 07:13:28 EDT 2000


Enumerations that hard-code to integers are more useful than
dictionaries in at least two cases. These are hard-realtime
implementation of the states and classes of finite state machines
and colored Petri nets whose transitions vary at run-time. 

(Since the transitions vary, they cannot be hardcoded as gotos. Hash
coded dictionaries would add a few cycles of overhead to lookup the
value of each enumeration. The hard realtime requirement means that
it would be required to know the worst case number of cycles added,
and that there could be no possibility of memory leakages or hanging
pointers. An array lookup of a constant, on the other hand, takes a
predictable number of cycles.)

For non-realtime algorithms, especially involving user interaction,
I cannot think of an algorithm where a dictionary would not do in
place of an enumeration. But inside servers, medical instruments,
chips, orbitting satellites, semantic artificial intelligence
technologies, nuclear safety devices, Jini federations, autonomous
intelligent software agents, FAA airspace deconfliction, weapon
fail-safes, auto-pilots, military battle-shorts, and other
non-client applications, the stability and predictability of code is
more important than speed. 

Admittedly, Python is not commonly used aboard satellites that must
run reliably for 30 years. But Python is quick to code in. It is
therefore being used to prototype algorithms that will be
reimplemented in hard realtime technologies including Ada and, where
permitted by license, realtime Java. Currently various Java and C++
tool licenses forbid the use of those languages/tools for military,
medical instruments, or any life-saving devices, and, until the
hanging pointer and memory leakage problems are solved, it is good
to think about where exactly are hard realtime techinques needed
versus where hangs, wait states, reboots, reformats, and reinstalls
are okay.

Mike Brenner
The MITRE Corporation


Cameron Laird wrote in message ...
>I'll say that more forcefully than Aahz does here:  while
>enums are often a marker of good taste in C coding, Python
>generally achieves the same results with a considerably
>cleaner reformulation in terms of dicts.  If you feel a
>need for enums while writing Python, you're probably missing
>out on a better (and not-so-reminiscent-of-C) coding.
>
>I've become rather dogmatic on this point.  I need the
>practice of working to falsify it.  If you have a specific
>algorithm you can share that you see as ripe for a Python
>enum, please tell us here; maybe we can suggest an
>alternative.





More information about the Python-list mailing list