Implicit conversion to boolean in if and while statements

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Jul 16 06:20:40 CEST 2012


On Sun, 15 Jul 2012 20:21:41 -0700, Ranting Rick wrote:

> On Jul 15, 9:58 pm, Steven D'Aprano <steve
> +comp.lang.pyt... at pearwood.info> wrote:
>> On Sun, 15 Jul 2012 18:21:06 -0700, Ranting Rick wrote:
>> > If HOWEVER we want to "truth test" an object (as in: "if obj") we
>> > should be FORCED to use the bool! Why? Because explicit is better
>> > than implicit
>>
>> And this is why Rick always writes code like:
> ...
> 
> Traceback (most recent quip last):
>   Author: "<DeAprano>", line 7, in <post>
> LogicalFallacyError: "Reductio ad absurdum"


Deary deary me Rick. Reductio ad adsurdum is not a fallacy. It is a 
counter-argument to an argument or claim, by showing that the premise of 
the original claim leads to an absurd conclusion.

You have claimed that we should always be explicit whenever we write. But 
you do not actually live up to your own advice, because you can't: it is 
absurd to try to be explicit about everything all the time. You have 
misunderstood the purpose of the Zen of Python: it is not to claim that 
everything should be explicit, but to avoid code that is hard to 
understand because things which need to be explicit for clarity are 
implied by other parts of your code.

(It's not like explicit and implicit are distinct -- everything depends 
on something implicit, if only the meaning of the words you use to 
describe it.)

It certainly doesn't mean that the semantics of Python the language must 
be written out explicitly every time you use each feature.

for x in sequence:  # Yes, implies that we iterate over the values

for loop variable named x in iterable sequence iterate over values and 
assign the loop variable each time you go around the loop executing the 
following block each time:
    # No, since that tells us what we already know and just adds
    # meaningless verbosity for the sake of faux "explicitness"



-- 
Steven



More information about the Python-list mailing list