Controlling a generator the pythonic way

Thomas Lotze thomas at thomas-lotze.de
Sat Jun 11 19:48:42 EDT 2005


Peter Hansen wrote:

> Fair enough, but who cares what the generator code thinks?  It's what the
> programmer has to deal with that matters, and an object is going to have a
> cleaner interface than a generator-plus-mutable-object.

That's right, and among the choices discussed, the object is the one I do
prefer. I just don't feel really satisfied...

>> It does, however, require a lot of attribute access, which does cost
>> some cycles.
> 
> Hmm... "premature optimization" is all I have to say about that.

But when is the right time to optimize? There's a point when the thing
runs, does the right thing and - by the token of "make it run, make it
right, make it fast" - might get optimized. And if there are places in a
PDF library that might justly be optimized, the tokenizer is certainly one
of them as it gets called really often.

Still, I'm going to focus on cleaner code and, first and foremost, a clean
API if it comes to a decision between these goals and optimization - at
least as long as I'm talking about pure Python code.

-- 
Thomas



More information about the Python-list mailing list