3 ms·
My favorite way to write that is with expression oriented langauges. Example in OCaml: x = if condition() then 5 else 4 I dislike how the regular order of
by Zababa 5y ago
My favorite way to write that is with expression oriented langauges. Example in OCaml:
x = if condition() then 5 else 4
I dislike how the regular order of if is changed when used as an expression. I don't know how you could retrofit that into existing Python tough. Probably a consequence of defining blocks with whitespaces.
- kbenson 5y agoYeah, Python's willingness to break up conceptual concepts into separate parts of an expression such that you might need to backtrack while reading has always seemed an odd choice to me, exemplified by list comprehensions, especially when nested.
- mixmastamyk 5y agoIt is simply a design choice, the common value is given first. Comprehensions in Py are the same.
- Zababa 5y agoSure it's a design choice but, quoting the Zen of Python: > Special cases aren't special enough to break the rules. > There should be one-- and preferably only one --obvious way to do it. Both are broken by the existance of 2 if syntaxes depending on the context.
- DonHopkins 5y agoBut when you write "condition ? first : second" or "(if condition first second)", the first common value is still given before the second uncommon value, so what's the advantage of putting the condition BETWEEN first and second, instead of BEFORE? After all, the condition has to be EVALUATED first before deciding which one to use. Infix "if" conditions just scramble up the order of evaluation from the order of program source code.
- mixmastamyk 5y agoThe argument is that the most common value should be first and the rest can be thought of as rare and almost ignored. I don’t always agree, but still prefer it to C syntax which I have to look up every time.