guber@lemmy.blahaj.zone to Lemmy Shitpost@lemmy.world · 5 months agoproportional reactionlemmy.blahaj.zoneimagemessage-square15linkfedilinkarrow-up11arrow-down10
arrow-up11arrow-down1imageproportional reactionlemmy.blahaj.zoneguber@lemmy.blahaj.zone to Lemmy Shitpost@lemmy.world · 5 months agomessage-square15linkfedilink
minus-squareBeigeAgenda@lemmy.calinkfedilinkarrow-up0·5 months agoDon’t you just love the readability a = a > b ? (b > c ? (a < d ? c : a) : d) : (b < c ? a : d )
minus-squarekryptonianCodeMonkey@lemmy.worldlinkfedilinkarrow-up0·5 months agoWeird example. 3 nested conditionals is not the typical use case for a ternary, and 2 of the 5 branches result in a pointless a=a assignment. I agree this is bad code, but it’s just as bad and hard to parss in a normal if-else structure too: if (a>b) { if (b>c) { if (a<d) { a=c; } else { a=a; } } else { a=d; } } else { if (b<c) { a=a; } else { a=d; } } In another situation, though, it’s perfectly readable to have a much more typical ternary use case like: a = c > d ? c : d And a pair of parentheses never hurt readability either: a = (c > d) ? c : d
Don’t you just love the readability
Weird example. 3 nested conditionals is not the typical use case for a ternary, and 2 of the 5 branches result in a pointless a=a assignment. I agree this is bad code, but it’s just as bad and hard to parss in a normal if-else structure too:
if (a>b) { if (b>c) { if (a<d) { a=c; } else { a=a; } } else { a=d; } } else { if (b<c) { a=a; } else { a=d; } }In another situation, though, it’s perfectly readable to have a much more typical ternary use case like:
a = c > d ? c : dAnd a pair of parentheses never hurt readability either:
a = (c > d) ? c : d