__call__ bad style? (was Re: Callable modules?)

Alex Martelli aleax at aleax.it
Thu Jul 25 08:00:33 EDT 2002


Jonathan Hogg wrote:
        ...
>> I prefer simplicity.  "Do the simplest thing that can possibly work".
>> As you're showing, __call__ encourages tossing simplicity away.
> 
> Hah. You've got me there :-)
> 
> Yes, I believe in adding infrastructure that I know
> the-day-after-tomorrow, I'll be glad I did ;-)

Bingo.  I had much the same approach for the first 20 years
or so of my programming career, then it FINALLY started
dawning on me that much of my "sure to be useful eventually"
infrastructure WASN'T.  When a short time later the XP guys
finally started writing this idea down, worded quite well as
the "You Ain't Gonna Need It" principle, that was one of the
many things they wrote which went *PING!* in my head.  I
prefer to shorten the principle's name to "Ain't Gonna Need
It", because that makes its acronym AGNI (Hindu God of Fire),
AND because the "you" is actually redundant if I understand
"slang grammar" correctly (isn't the great song's title just
"Ain't Misbehavin'" without any pronoun?-).  But that's by the
by.

> 'repr' is one of those things. I do a lot of work
> at the prompt and being able to examine objects is a critical part of that
> for me.

When I write a closure, its repr is the inner function's name
and ID, which is most often sufficient.  When I need to inspect
object behavior, Python makes it a snap to code object inspectors
*WITHOUT* loading down the production version of those objects
with any complication whatsoever.  This "does the simplest thing
that can possibly work" for EACH separate need: having objects
that work with no extra baggage whatsoever, AND having a nice
interactive environment -- the latter's needs vary widely
depending on WHAT interactive environment we're talking about,
after all (bare Python prompt vs richer IDE's).

Admittedly the "infrastructure overhead" is tiny here, anyway.
But if I had to make everything a class instance, just to ensure 
that all relevant state was in nicely named attributes, that
pleasant things happen if i print the object or pickle it or
add it to a quaternion, I'd never get any real work done.  AGNI.
Or, Matthew 6:34, if you prefer:-).


> I guess we'll just have to agree to disagree on what counts as a "wart"
> and "rare and weird" ;-)

Yep, we'd better:-).


Alex




More information about the Python-list mailing list