Python Patterns

Alex Martelli aleaxit at yahoo.com
Tue Oct 5 17:56:19 EDT 2004


Irmen de Jong <irmen at -nospam-remove-this-xs4all.nl> wrote:
   ...
> I really should dust off my old GOF Desing Patterns book,
> because your code made me remember the "state" pattern right away :-)
> 
> There should be a Python version of that book... I think that

Yep -- I've been writing about DPs with/for Python for years now (that's
the invariable background to almost all of my conference talks &c, check
most of them out at www.strakt.com), and one day (once I'm done doing
2nd editions of cookbooks and nutshells;-) I hope to write a book about
that (plus materials on agile programming practices, again with Python
as the explanatory language).  That's what I _wanted_ to write from day
one, but I'm glad it didn't materialize yet... it will be a much better
book for the wait;-).  Meanwhile Robert Martin has already written a
book far closer than any other to what I had in mind -- but he uses C++
and Java as explanatory languages, and _that_ will give MY book enough
of an edge to almost catch up with Uncle Bob's awesome experience and
writing skills...!-)

> the patterns in it are very easily expressed in Python, and
> that Python allows for many other interesting patters ('Borg', to
> name one).

Yep, I'm reasonably familiar with that one;-)

> This "state" pattern needs a clumsy internal state object in C++
> but in Python we can just change the object's class directly,
> which is a much more direct implementation of what the pattern
> tries to achieve :-)

Right, good point.  In C++ you can do something closer with the Strategy
pattern -- still one level of indirectness, but a consistent set of
methods (embodied in the one strategy object) commuted as a whole.
Assigning __class__ IS of course more direct, yes;-).

> Thanks Alex

You're most welcome -- thank YOU for your feedback!


Alex



More information about the Python-list mailing list