guber@lemmy.blahaj.zone to Lemmy Shitpost@lemmy.world · 1 day agoproportional reactionlemmy.blahaj.zoneimagemessage-square43fedilinkarrow-up1156arrow-down118cross-posted to: onehundredninetysix@lemmy.blahaj.zone
arrow-up1138arrow-down1imageproportional reactionlemmy.blahaj.zoneguber@lemmy.blahaj.zone to Lemmy Shitpost@lemmy.world · 1 day agomessage-square43fedilinkcross-posted to: onehundredninetysix@lemmy.blahaj.zone
minus-squarethebestaquaman@lemmy.worldlinkfedilinkarrow-up2·19 hours agoI honestly can’t see how this is more readable than x = (y > 5) ? "foo" : "bar" I get that it’s a syntax that needs to be learned, but it’s just so clean and concise!
minus-squarecalcopiritus@lemmy.worldlinkfedilinkarrow-up3·12 hours agoBecause it can be done for multiple lines too. And you can do else-if too. Also, “if” and “else” is more recognizable than “?” and “:” x = if y > 5 { println!("Y was over 5"); z + 5 } else if y < 0 { handle_negative_y(y); z - y } else { println!("<WARN> unexpected value for y"} 0 }
minus-squarefour@lemmy.ziplinkfedilinkEnglisharrow-up1·16 hours agoWhat I like about using if and else for that is that you’re already using those keywords for branching in other parts of the code. Though my least favorite is probably Python’s: x = "foo" if y > 5 else "bar" It just seems backwards to me
minus-squareUnfortunateShort@lemmy.worldlinkfedilinkEnglisharrow-up1·edit-24 hours agoBecause Python wants you to read it like English: x is “foo” if y is greater than 5, else it is “bar”
minus-squarethebestaquaman@lemmy.worldlinkfedilinkarrow-up1·edit-214 hours agoWhile Python’s version does feel a bit backwards, it’s at least consistent with how list comprehensions are set up. They can also feel a bit “backwards” imo, especially when they include conditionals.
minus-squarefour@lemmy.ziplinkfedilinkEnglisharrow-up1·13 hours agoList comprehension is another thing I don’t like about Python :) There’s more of those, but one thing I do like about Python is that I get paid for writing it, so I try not to complain too much
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up2·12 hours agoI love list comprehension. Best part of the language, imo. To each their own.
I honestly can’t see how this is more readable than
x = (y > 5) ? "foo" : "bar"
I get that it’s a syntax that needs to be learned, but it’s just so clean and concise!
Because it can be done for multiple lines too. And you can do else-if too. Also, “if” and “else” is more recognizable than “?” and “:”
x = if y > 5 { println!("Y was over 5"); z + 5 } else if y < 0 { handle_negative_y(y); z - y } else { println!("<WARN> unexpected value for y"} 0 }
What I like about using
if
andelse
for that is that you’re already using those keywords for branching in other parts of the code.Though my least favorite is probably Python’s:
x = "foo" if y > 5 else "bar"
It just seems backwards to me
Because Python wants you to read it like English:
x is “foo” if y is greater than 5, else it is “bar”
While Python’s version does feel a bit backwards, it’s at least consistent with how list comprehensions are set up. They can also feel a bit “backwards” imo, especially when they include conditionals.
List comprehension is another thing I don’t like about Python :)
There’s more of those, but one thing I do like about Python is that I get paid for writing it, so I try not to complain too much
I love list comprehension. Best part of the language, imo. To each their own.