Coding style

Daniel Dittmar daniel.dittmar at sap.corp
Tue Jul 18 13:03:07 EDT 2006


Patrick Maupin wrote:
> The argument that one should always use len() to test whether sequences
> are empty or not simply because the use of len() gives a free "is it a
> sequence?" type-check is not apt to be well received by an audience
> which rejects explicit type-checking in general.

No explicit type check. More of an implicit behaviour check. OK,
wise guys are not apt to be well received by  ... well, any audience.

> The perverse wish, expressed in the specific example, that SOME piece
> of code SOMEWHERE should PLEASE throw an exception because some idiot
> passed a generator expression rather than a list into a function, is
> not apt to be well received by an audience which strives for generality
> when it makes sense; and I daresay most members of that audience, if
> confronted with the wished-for exception, would fix the function so
> that it quite happily accepted generator expressions, rather than
> changing a conditional to use len() just so that an equivalent
> exception could happen a bit earlier.

Premature generalization: the new 'premature optimization'.

Daniel



More information about the Python-list mailing list