this post was submitted on 08 Dec 2023
616 points (96.4% liked)
Programmer Humor
32467 readers
1078 users here now
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.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
If condition then this else that vs this ?? that
Which option do you think requires less time for a person to identify and understand?
Sure if it's just your own code do whatever comes natural to you but there's a reason we don't use these kind of logical operators in day to day speech is my point.
Ive been a backend dev for 2 years now and I've never come across the ?? operator and every time I come across a ternary operator I have to Google in what order comes what.
Not saying it doesn't make the code more concise and less "noisy" but sometimes a simple if else statement just makes the code easier to mantain
It’s easier to mess up
return a != null ? a : b
than it isreturn a ?? b
, and operators work from left to right.