On Wed, Dec 10, 2014 at 11:10 AM, Steven D'Aprano
<steve+comp.lang.pyt...@pearwood.info> wrote:
> On the other hand, *premature optimization*. In general, one shouldn't write
> more complex code so the compiler can optimize it, one should write simpler
> code and have a smarter compiler. If *we* are capable of recognising that
> iters is not modified in the body of the loop, then the compiler should be
> capable of it too. (If it isn't, it is because nobody has bothered to give
> the compiler sufficient smarts, not because it can't be done.) So a good
> compiler should be able to compile "while iters" into "if iters: while
> True" so long as iters is not modified in the body of the loop.

In general, one can't expect the boolification of a Python object to
be consistent, so the compiler can't optimize this. How can it be sure
the list will never become empty?

I'm still of the opinion that a while loop's header implies something
about the code; "while iters:" implies that iters might be able to
become false. Sure, you can verify easily enough that it never will...
but why should you have to verify at all?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to