Re: Coding style
- From: Donn Cave <donn@xxxxxxxxxxxxxxxx>
- Date: Mon, 17 Jul 2006 14:16:43 -0700
In article <mailman.8257.1153158306.27775.python-list@xxxxxxxxxx>,
Steve Holden <steve@xxxxxxxxxxxxx> wrote:
tac-tics wrote:....
I'd say the second one. Empty lists are not false. They are empty.
Long live dedicated boolean data types.
Take them off to where they belong!
Tac-tics is right, an empty list is not False.
Anyway, just for some variety, I think (2) is preferrable
to (1), as is the following
while 1:
try:
lst.pop()
except IndexError:
break
Rather than blindly apply familiar patterns to our work,
I think everyone would agree that coding style in matters
like this should follow the underlying point of the code.
In this case, the body of the test refers implicitly to
the length of the list, since .pop() -> (list[a], list[:a])
where a is (len(list) - 1) It's therefore quite appropriate
for the test to be length.
Donn Cave, donn@xxxxxxxxxxxxxxxx
.
- Follow-Ups:
- Re: Coding style
- From: Erik Max Francis
- Re: Coding style
- References:
- Coding style
- From: PTY
- Re: Coding style
- From: Simon Brunning
- Re: Coding style
- From: tac-tics
- Re: Coding style
- From: Steve Holden
- Coding style
- Prev by Date: Tkinter StringVar mystery
- Next by Date: Re: Coding style
- Previous by thread: Re: Coding style
- Next by thread: Re: Coding style
- Index(es):
Relevant Pages
|