Coding style
Steve Holden
steve at holdenweb.com
Tue Jul 18 02:42:40 EDT 2006
tac-tics wrote:
> dwelch91 wrote:
>
>>tac-tics wrote:
>>
>>>I'd say the second one. Empty lists are not false. They are empty. Long
>>>live dedicated boolean data types.
>>>
>>
>>Uh, no, empty lists are False in a boolean context:
>>
>>http://docs.python.org/lib/truth.html
>>
>>-Don
>
>
> Perhaps I should have specified it like this:
>
>
>>>>empty_list = []
>>>>empty_list is not False
>
> True
>
> I'm well aware that both of these snippets does the same thing. I'm
> just spouting my opinion that lists and integers are not tests, and in
> an ideal world (Java??? X-) if statements support only boolean types.
>
> DISCLAIMER: I do not promote the use of Java.
>
You don't promote use of Python either if you deliberately ignore
programming paradigms that have stood the test of time. Under what set
of rules could it make sense to test a list for equality with a Boolean
value (note also that capital "B": the word is based on someone's name).
The
if lst:
metaphor is so well established as a means of guarding statements that
should be executed only when there are elements in the list (or other
container, come to that), promoting any other way to perform the test
will only lead to confusion: there should be one (and preferably only
one) obvious way to do it.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list