Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upProposal: if <expr> then <expr> else <expr> #98
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
fuzzthink
Nov 29, 2014
Agree. Even as a long time pythonist, python's way always feels backwards to me; it goes against every single language's ternary flow and doesn't read as well.
fuzzthink
commented
Nov 29, 2014
|
Agree. Even as a long time pythonist, python's way always feels backwards to me; it goes against every single language's ternary flow and doesn't read as well. |
alongubkin
added
proposal
need-feedback
labels
Nov 29, 2014
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
Namek
Nov 29, 2014
Collaborator
TL;DR; I'm not sure. BUT!...
It depends how you look at it. Let's get rid of "else ". Then let's compare this (oh dear gamedev):
if isCardBonusable(card) then Bonus.create(...)
to this:
Bonus.create(...) if isCardBonusable(card)
NOW let's assume that you read from left to right. First what you can see in second example is Bonus.create(...). And what is this? The default expected value. That's what you're most interested in. Little less interesting is when it's Bonus.create(...) so in second place we can see if isCardBonusable(card). The effect is that you don't have (by reading left-to-right) to read and understand whole line, while in the first example - you do. Second one wins.
But to be authentic myself, I noticed that it's like fighting with stupid habits. And behaviour "I like it better because I've seen it first in my life" is a stupid habit. So let's go back to me being authentic - years ago I would agree with @BrianTMaurer and @fuzzthink. Now I'm not sure.
To see it more alive.
Some other example (taken from WebSocket implementation in ActionScript):
return header.length == 2 ? {
name: header[0],
value: header[1]
} : null;
return {
name: header[0],
value: header[1]
} if header.length == 2;
What's more important? Condition or returning value?
And the last short comparison:
var bonus = Bonus.create(...) if isCardBonusable(card);
vs
var bonus = if isCardBonusable(card) then Bonus.create(...);
which is better and why? You know my arguments.
|
TL;DR; I'm not sure. BUT!... It depends how you look at it. Let's get rid of "else ". Then let's compare this (oh dear gamedev): NOW let's assume that you read from left to right. First what you can see in second example is But to be authentic myself, I noticed that it's like fighting with stupid habits. And behaviour "I like it better because I've seen it first in my life" is a stupid habit. So let's go back to me being authentic - years ago I would agree with @BrianTMaurer and @fuzzthink. Now I'm not sure. To see it more alive. Some other example (taken from WebSocket implementation in ActionScript):
What's more important? Condition or returning value? And the last short comparison: which is better and why? You know my arguments. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nmussy
Nov 29, 2014
While I agree that it's a familiarity issue, the if <cond> then <expr> vs. <expr> if <cond> is a case of what the interpreter reads vs. what I want it to do.
if blocks aren't parsed if the condition isn't met, whilst the <expr> if <cond> reads like "Okay, now I do that... oh, wait, never mind." I don't think JavaScript or Spider are high level enough for us to detach ourselves from the way they will be interpreted, if that makes any sense.
nmussy
commented
Nov 29, 2014
|
While I agree that it's a familiarity issue, the
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nmn
Dec 1, 2014
My opinion on this is that familiarity with the JS should be preferred in all cases. In this case, JS has no similar feature any way.
nmn
commented
Dec 1, 2014
|
My opinion on this is that familiarity with the JS should be preferred in all cases. In this case, JS has no similar feature any way. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Please no, not lua. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
nmn
commented
Dec 5, 2014
|
@zekesonxx Please elaborate a little. |
BrianTMaurer commentedNov 29, 2014
To improve "natural" left-to-right readability I would love to see
if <expr> then <expr> else <expr>;expressions.