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

Greg Ewing greg@cosc.canterbury.ac.nz
Tue, 27 Nov 2001 16:12:17 +1300 (NZDT)


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.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+