I come to praise .join, not to bury it...

James_Althoff at i2.com James_Althoff at i2.com
Fri Mar 16 14:40:15 EST 2001


All joking aside ...

Although overloading __if__ is not so common, overloading the equivalent of
"__for__  __in__" is a very common, convenient, and powerful design pattern
in Smalltalk  (see "Smalltalk Best Practice Patterns", Kent Beck, 1997,
ISBN 0-13-476904-X, page 146).  The idea is that for a collection class you
define a "do:" method that takes a block of code as the argument (this is
very easy to do in Smalltalk).  When invoked, the "do:" method in the
collection class executes the code block for each item in the collection.
That way the collection class does not have to export artifacts like lists,
iterators, or indexed-access to contained items just so that the collection
can be used inside built-in looping control structures (such as "for in").
Rather, the collection class takes care of the iteration across its
contained items in its own internal implementation.  The Python equivalent
defining a method that takes as the argument a pre-defined function (too
inconvenient to have to create a function for a random block of code -- and
lambdas can't have statements) or a code-string to eval or exec (too slow
and unreadable) is not anywhere near as convenient or usable, so this
design pattern is rarely seen in Python programs (compared to just pulling
each item out of the collection in a "for in" or "while" loop).

Jim






                                                                                                                   
                    "Ken Seehof"                                                                                   
                    <kens at sightreader.        To:     <python-list at python.org>                                     
                    com>                      cc:                                                                  
                    Sent by:                  Subject:     Re: I come to praise .join, not to bury it...           
                    python-list-admin@                                                                             
                    python.org                                                                                     
                                                                                                                   
                                                                                                                   
                    03/15/01 09:47 AM                                                                              
                                                                                                                   
                                                                                                                   




Hmm ... I wonder what I'd do if I could overload __if__ ...

Hey, I know!  You could use it to implement fuzzy logic for quantum
computers.

The new __if__ would cause multiple superimposed quantum states based on
the
probability wave distribution of the quantum bit argument.

----- Original Message -----
From: "Darren New" <dnew at san.rr.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
Sent: Thursday, March 15, 2001 12:15 PM
Subject: Re: I come to praise .join, not to bury it...


> Alex Martelli wrote:
> > And then again, the _appearance_ that too much emphasis
> > was being placed on syntax-sugary issues kept me *AWAY*
> > from Python for longer than it should have
>
> Actually, what I found quite cool about Python is that the procedural
syntax
> maps to OO semantics. I.e., in Smalltalk, everything looks like a method
> call, including "if". In Eiffel, everything that isn't a method call
doesn't
> look like a method call, and vica versa. But in Python, the convenient
and
> familiar "x = y[5:10]" maps to a real live method call you can override.
>
> Well, *I* thought it was neat. It lets you be OO where you want, and
keeps
> it out of your face otherwise.
>
> --
> Darren New / Senior MTS & Free Radical / Invisible Worlds Inc.
> San Diego, CA, USA (PST).  Cryptokeys on demand.
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--
http://mail.python.org/mailman/listinfo/python-list








More information about the Python-list mailing list