Re:Anti-If: The missing patterns (2016)
by hellofunk on Wednesday June 27, 2018 @11:44AM
(#17409079)
I'm curious, what about "x && y" is "python-style" ?
It's been in nearly all languages, and for decades before python existed.
Re:Anti-If: The missing patterns (2016)
by jstimpfle on Wednesday June 27, 2018 @12:29PM
(#17409488)
It was not about "x && y" but about the construct from the parent post as a whole. It never uses y in a boolean context, but only as a value. So I was thinking y could be anything. In python this is how it works:
>>> 0 and 'asdf'
False
>>> 3 and 'asdf'
'asdf'
>>> 3 and ''
''
'and' and 'or' in python are short-circuited as in e.g. C, but it's even more short-circuited! The "last" component is not evaluated in a boolean context. For a complete evaluation you have to use the expression in an if or while statement or apply the bool() function. I would say it's like a monad, if that helps.
Re:Anti-If: The missing patterns (2016)
by hellofunk on Wednesday June 27, 2018 @03:03PM
(#17410840)
What you are talking about has nothing to do with short circuiting.
Re:Anti-If: The missing patterns (2016)
by jstimpfle on Wednesday June 27, 2018 @07:08PM
(#17412682)
Agreed, bad choice of words. It's only somewhat similar. Maybe "lazy" would be a better term. Whatever, man! I hope it's clear what I meant.
It’s not that you’re unclear, it’s that it is irrelevant to the discussion, as you were talking about a fairly trivial and unrelated language feature — and it is also a feature that exists in many languages, hardly unique to python.
Regarding which way is better, there's not much benefit arguing one way or the other. This is a leaf decision. It doesn't affect the structure of other parts of the code.