[Python-Dev] re: PEP 275: Switching on Multiple Values, Rev 1.2

M.-A. Lemburg mal@lemburg.com
Tue, 27 Nov 2001 11:07:20 +0100


Greg Ewing wrote:
> 
> Brian Slesinsky <bslesins@best.com>:
> 
> > But sometimes you need to work with base types or other people's
> > classes without subclassing them
> 
> I think there are situations where it's legitimate to prefer a
> case-statement approach even when dealing with your own classes.
> 
> I once wrote a compiler in HUGS (a Haskell dialect), and I found it
> very convenient to be able to write a self-contained function which
> took a parse tree node and did something for each possible subtype of
> that node. It kept all the processing related to each phase of the
> compiler together in one place.
> 
> Using a pure OO aproach, I would have had to scatter it all among
> hundreds of one or two-line methods of many classes, and probably
> would have gone insane before finishing the project.

Right. IMO, the method callback approach is nice if you need
an extendable architecture, e.g. to write generic parsers
frameworks. It doesn't pay off in situations where you have 
a set of fixed requirements. In these cases, the performance
gain is more important than being able to extend by 
subclassing.

-- 
Marc-Andre Lemburg
CEO eGenix.com Software GmbH
______________________________________________________________________
Consulting & Company:                           http://www.egenix.com/
Python Software:                        http://www.lemburg.com/python/