Coding style

Paul Rubin http
Tue Jul 18 01:40:13 EDT 2006


"Carl Banks" <pavlovevidence at gmail.com> writes:
> What if you called the function like this:
> 
>     process_values(x.strip() for x in values_lst)
> 
> Oops, now we've just gone through an expensive initialization and
> finalization for nothing (since values_lst was empty).  Maybe some
> subtle bugs introduced.  If we're lucky, the finalization step will
> throw an exception.

You've got a function written to take a list arg and are passing it
something other than a list.  Why do you expect it to work?
As soon as the function uses lst[3] for something, it will crash
if you pass it a sequence like that.  Your example is mainly an
argument for static type checking.



More information about the Python-list mailing list