PEP218: Representing the empty set

Peter Hansen peter at engcorp.com
Wed Feb 18 11:41:34 EST 2004


Paul Rubin wrote:
> 
> Peter Hansen <peter at engcorp.com> writes:
> > I think the example I would have in mind is a comparison:
> >
> > if a == []:
> >     # do something
> >     if b != {}:
> >         a.append(b)
> >
> > or whatever....  If the empty item
> > is merely a temporary, to be used and discarded, then the apparent
> > extra overhead of the call, and the less succinct syntax, lead me to
> > think the short form is preferable.
> 
> But you suffer the overhead either way.  The {} syntax may be worse
> than the function call syntax because it looks like it avoids the
> overhead when it really doesn't.  The correct way to avoid the
> overhead is with "if len(b) != 0: ... ".

Who said this was about overhead?  Oh, wait, you thought I did...
because of the part where I said "overhead". :-)

I didn't mean that what is important is whether or not there *is*
actual overhead.  Merely that the one approach, with the literal,
fits more easily in the brain and "feels" better.  Whether this is
because one (mistakingly) believes at some low level that it has
less overhead or not is irrelevant.  

Given the option, perhaps even if it had *higher* overhead, I would
still prefer the more readable (to me) literal form.

-Peter



More information about the Python-list mailing list