A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-October/017993.html below:

[Python-Dev] re: conditional expressions

[Python-Dev] re: conditional expressionsTim Peters tim.one@home.com
Wed, 17 Oct 2001 22:08:03 -0400
[Greg Wilson]
> I just showed the proposed conditional expression syntax
> to two colleagues, and asked them how they would write
> the "sign" function (-1 for negative, 0 for zero, +1 for
> positive) using it.  Both of them wrote:
>
>     s = if x < 0 then -1 elif x == 0 then 0 else 1
>
> (Well, OK, one of them tested negative, then positive, then
> returned zero as the 'else', but that's a quibble.)

Quibble?  A professor in college took points off one of my programs because
I didn't test for 0 first.  He explained that testing for either negative or
positive first left you vulnerable on 1's-complement machines, where
comparisons for <0 or >0 just checked the sign bit, and either form of
1's-comp 0 would pass one of those tests.  I looked at him like he was
insane.  He looked at me the same way.  He was old enough that I suppose
he's dead now.  Ha!  I win <wink>.

elif-is-file-spelled-backwards-ly y'rs  - tim




RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4