Coding style

Donn Cave donn at u.washington.edu
Tue Jul 18 13:07:33 EDT 2006


In article <1153232735.118387.12130 at 75g2000cwc.googlegroups.com>,
 "Carl Banks" <pavlovevidence at gmail.com> wrote:

> 1. This is fine in a perfect world where all code clearly conforms to
> expectation.  Problem is, a lot doesn't.  I think it's quite easy to
> accidentally check something intended as an iterable for emptiness.
> And, as I've explained in other posts, this can lead to subtle bugs.
> Whereas if you check for emptiness using len, it throws an exception
> right away, no bugs.  It's safer to use len.  (Safest of all is not to
> check for emptiness at all.)

Yes, it's clearly more direct to catch IndexError, than to
try to anticipate it.

   Donn Cave, donn at u.washington.edu



More information about the Python-list mailing list