"object" vs "dynamic" programming styles
Alex Martelli
aleaxit at yahoo.com
Sun Mar 25 12:10:05 EST 2001
"Just van Rossum" <just at letterror.com> wrote in message
news:3ABD2390.A2A28A12 at letterror.com...
[snip]
> My personal preference would definitely be version 3, the factory
function.
> Less magic, clearer code.
Seconded!!! Indeed: thirded, fourthed, etc...
> When I first started writing OO code (which was with Python) I was often
> tempted to do lots of smart things in the __init__ method. But it only
> makes things harder in the long run. I recently had to extend a module I
> had written a few years back: all the smart things in the __init__ were
> of no use to me now: it assumed a quite different usage.
> So I changed the __init__ to be as simple as possible, and added a couple
> of factory functions. It's all nice and clean now...
An absolutely crucial consideration. Temptation's even greater in
languages offering the ability to provide multiple overloaded
constructors -- that makes it even easier to yield to the temptation
to perform too much clever magic in the constructor[s]. Factory
functions rule...
Alex
More information about the Python-list
mailing list