osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tutor] beginning to code


Op 19-09-17 om 09:40 schreef Chris Angelico:
> On Tue, Sep 19, 2017 at 5:10 PM, Antoon Pardon <antoon.pardon at vub.be> wrote:
>
>> I don't find it really usefull. How useful is it that you can type
>> if a: instead of if a != 0: ? I have yet to encounter a situation
>> where I thought: Yes I want to execute this piece of code when
>> a value is Falsy and an other piece when that same value is Truthy.
> Okay. Let me ask you a different question.
>
> Given that you can do this:
>
>     if x > 5:
>
> should you be able to do this:
>
>     condition = (x > 5)
>     if condition:
>
> ? If "no", then you've just downgraded booleans to less than
> first-class values. If "yes", then you've just opened up the
> possibility for "if x:", and you have to draw the line somewhere -
> what can you and what can't you use that way? It's now syntactically
> legal to use "if x:" with any type of object, so you have to either
> define the truthiness/falsiness of everything, or have some of them
> raise TypeError.

Yes you have to draw the line somewhere. But there is a difference
between one the one hand stating that the line had to be drawn somewhere
and that through design and history this is what we ended up with and
although it may be interesting to argue the pro and con of this and
various other possibilities, this is workable and so highly unlikely
to change.

or on the other hand stating or suggesting this is the obvious place
to draw that line and we would miss something really useful had the
line be drawn somewhere else.

-- 
Antoon Pardon