Who am I: can a class instance determine its own name?

Alex Martelli aleaxit at yahoo.com
Mon Mar 19 07:48:53 CET 2001

"Carlos Ribeiro" <carribeiro at yahoo.com> wrote in message
news:mailman.984971963.29821.python-list at python.org...
> Alex Martelli wrote:
> >(My dream is actually of a collection of bits in an attribute...
> While I agree on the *principle*, I disagree on the details. Thinking

Yeah, yeah, you're right: the dream is actually about an attribute
that is a set of atoms; that they're representes as bits, or not, is
not essential to the dream.

> this as a bitmap is an artifact of historic optimization techniques. Worse

The isomorphism between sets on a universe of N atoms and N-bit
integers is hardly 'an artifact' -- it's a simple mathematical reality
which _enables_ certain 'optimizations' (e.g., enumerating all such
sets by enumerating all such integers).

> OTOH, having a set of attributes would make the code more readable and
> extensible. (the set of attributes is itself in a dictionary and would
> be subject to the same control).

Once we do start talking about implementation details, the issues
shift.  Python has no builtin 'set' type, so any set must be mapped
by some other type -- be it an integer, dictionary, string, whatever.
And I disagree with your contentions about what might be the
best mapping of this particular set.

I see no difference in readability between:

    adict.unchangeable |= 1


    adict.unchancheable[1] = 1

for "adding an element to the set" (in either case, of course, you
could use a symbolic name for the 1 that represents the atom --
no difference here).  When I want to add several elements at
the same time,

    adict.unchangeable |= ( 1 | 2 )

(or symbolic-named equivalent) has it all over alternatives a
dictionary (currently) affords.

Extensibility (to a set from a universe of N+n atoms) is clearly
equally feasible in either case.  And the 'nesting' whereby each
dictionary holds a dictionary (and so on ad infinitum) is complex
and tricky -- "dictionaries all the way down" can't be really
implemented, of course, so that some kind of magic would have
to be used to break the chain at some point; give me the utter
simplicity of the bitmap-representation of sets over that...!


More information about the Python-list mailing list