That makes sense to me and there a probably plenty of examples.
However, I worry more about other examples that will fail
and do so it a way that is nearly impossible to find through
code review (because the code IS correct as written).

 n = len(log_entries)
 if log_entries[n] in handled:

This should raise an IndexError. I think you meant something else?

    log_entries.pop(n)

Right. It should have been n-1 in my quick example.
The idea is that if the len() return value is actually being use for something
(in this case indexing, but possibly also slicing, resource managment, etc),
then the app will silently start doing the wrong thing.

 next_ticket_number = len(tickets)
 create_new_ticket_form(time(), next_ticket_number)

ISTM, there are many uses for len() when it is bad news if the result
is less than the real length.  Those cases will be harder to detect and
correct than if an overflow was raised.

Raymond

_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to