Big time WTF with generators - bug?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Feb 13 15:00:07 EST 2008


Paul Rubin:
> Even with that though, at least for me, Python starts feeling really
> scary when the iterators get this complicated.  I start wishing for
> a static type system, re-usable iterators, etc.

This is an interesting topic. I agree with you, I too was scared in a
similar situation. The language features allow you to do some things
in a simple way, but if you pile too much of them, you end losing
track of what you are doing, etc.
The D language has static typing and its classes allow a standard
opApply method that allows lazy iteration, they are re-usable
iterators (but to scan two iterators in parallel you need a big trick,
it's a matter of stack). They require more syntax, and it gets in the
way, so in the end I am more able to write recursive generators in
Python because its less cluttered syntax allows my brain to manage
that extra part of algorithmic complexity necessary for that kind of
convoluted code.
The Haskall language is often uses by very intelligent programmers, it
often allows to use lazy computations and iterations, but it has the
advantage that its iterators behave better, and during the generation
of some items you can, when you want, refer and use the items already
generated. Those things make lazy Python code very different from lazy
Haskell code.

Bye,
bearophile



More information about the Python-list mailing list