Learning Python now coming from Perl

Roy Smith roy at panix.com
Tue Dec 9 14:31:02 CET 2008

Nick Craig-Wood <nick at craig-wood.com> wrote:

> >  On the other hand, leaving out the parens returns the function itself, 
> >  which you can then call later.  I've often used this to create data-driven 
> >  logic.
> I didn't say it wasn't useful, just that if you came from Perl like I
> did, it is an easy mistake to make ;-)


> OO lore says whenever you see a type field in an instance you've gone
> wrong - types should be represented by what sort of object you've got,
> not by a type field.

OO lore lives in an ivory tower sometimes :-)  I'm working with an existing 
system, where objects are marshaled on the wire as type codes followed by a 
type-specific number of bytes of data.  Internally, it calls these AnyVals 
and the concept is pervasive in the architecture.  I could work within the 
existing architecture, or I could try to fight it.

Yes, I could get rid of the dispatch table and create 20 or 30 classes to 
represent all the possible types.  I'd end up with several times as much 
code, most of it boilerplate.  Instead of having a dispatch table of 
read/write functions, I'd have a dispatch table of classes, each of which 
has a read method and a write method.  It doesn't buy anything, and I'd 
still have the type codes exposed because I need them to read and write 
values to the wire.

More information about the Python-list mailing list