Enumeration idioms: Values from different enumerations

Steven D'Aprano steve at REMOVETHIScyber.com.au
Mon Dec 19 15:41:54 CET 2005


On Mon, 19 Dec 2005 05:30:11 -0800, Ben Sizer wrote:

>> Enums are not conceptually subclasses of integers. Integers just happen to
>> be a useful method to implement enumerations.
> 
> Aren't they? They have discrete values, can be ordered and compared for
> equality, etc. 

Just like:

mammal, reptile, amphibian, bird, fish

They are discrete values, they can be ordered in many different ways
(alphabetically, by biological clade, by average number of genes, etc),
and compared for equality (fish is not bird). But they aren't numbers.

It is true that you can create a one-to-one mapping from integers to
enums, but then you can also create a one-to-one mapping from William
Shakespeare's sonnets to enums. That second implementation is,
unfortunately, rather impractical.


> I think the 'numerate' part of 'enumeration' is a hint
> here. 

It certainly is a hint, but not of what you think. It means they are
countable, not that they are numbers. You could try looking "enumerate"
up in the dictionary: it means to count, as in "by the time she finished
enumerating all my flaws, I felt three inches high".

> They certainly don't look much further from being integers than
> booleans do. 

You think?

hamburger, steak, fish, chicken, pizza

What meaning do you give to steak**fish? Should that meaning change if I
happened to have written pizza first instead of last?

The fact that they can be counted shouldn't fool you into thinking they
are numbers. 



-- 
Steven.




More information about the Python-list mailing list