You are viewing a single thread.
View all comments View context
4 points
*

In the given example I’d probably use a switch / match expression, but ternaries are usually more flexible than switches and I don’t think it’s an issue to write a nested ternary instead of if else statements.

permalink
report
parent
reply
2 points
*

ternaries are usually more flexible than switches

Which is bad for readability because the reader need to manually compute it to see whether it’s doing simple switching or not. Also it adds the question of “Why did the author use a nested ternary instead of a switch? Was it meant to do more but it got left out unintentionally?”

permalink
report
parent
reply
1 point

Yes, you need to read code to understand it. If else statements can also do the job of a switch, so the exact same argument applies.

permalink
report
parent
reply
2 points

The point is I don’t need to read a switch statement to know that it is a switch

permalink
report
parent
reply

Programmer Humor

!programmerhumor@lemmy.ml

Create post

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

  • Posts must be relevant to programming, programmers, or computer science.
  • No NSFW content.
  • Jokes must be in good taste. No hate speech, bigotry, etc.

Community stats

  • 6.4K

    Monthly active users

  • 1.5K

    Posts

  • 35K

    Comments