You are viewing a single thread.
View all comments
54 points

And no one on his team ever understood his code.

Sometimes being declarative is better than being “smart”

permalink
report
reply
49 points

The last panel is infinitely more readable than parsing the whole chunk of logic above. Maybe you’re just not used to this language’s (I think this meme used C#) null operators.

permalink
report
parent
reply
11 points

Yeah, I have very little programming experience, and even not knowing the code, I figured this one out. Super simplified and clear.

permalink
report
parent
reply
7 points

?? Profit

permalink
report
parent
reply
33 points

Sure, if the rest of the team is first semester CS students doing their first group project. This is not an obscure 1337 h4x0r trick only known to programming gods writing COBOL code inside banking mainframes, it’s a simple operator.

permalink
report
parent
reply
30 points

Sure, but null coalescing is a pretty common feature in modern languages. Once you know what ?? means you can apply it to a whole host of languages.

permalink
report
parent
reply
24 points

I’m confused on how this is difficult to understand. Put aside the fact that it’s just a regular operator that… I mean virtually everyone should know, how hard is it to google “what does ?? mean in [language]” which has the added benefit of learning a new operator that can clean up your code?

permalink
report
parent
reply
4 points

Well yeah but imagine you had to do that on most lines of the code? It would become very distracting imho. If you are in a team with people that have a lot experience and or will learn more anyway this is fine. But if you are in a team with not very good programmers which “will never learn” because they have other stuff to do, you should be careful when using code like this. Though I would prefer in the former of course.

permalink
report
parent
reply
5 points

Honestly, and I mean this sincerely, if you’re on a team where the nullable coalesce is going to be confusing after the first handful of times encountered… look for a new job. It doesn’t bode well for their ability to do their jobs.

This is like the guy at Walmart who needs hand holding each time they clean a machine, it’s a problem waiting to happen.

permalink
report
parent
reply
0 points

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

permalink
report
parent
reply
7 points

It’s easier to mess up return a != null ? a : b than it is return a ?? b, and operators work from left to right.

permalink
report
parent
reply
13 points

This is why I favor 3. It’s fairly concise while not being all that obscure. And even if you’re not 100% on that syntax, context provides decent intuition about what it does.

permalink
report
parent
reply
5 points
*

This is why I usually don’t comment on stuff like this in PRs. If it’s readable and easy to understand it doesn’t need more abstractions. Even if it’s less code. What’s it save like a few bytes? That’s not as useful as the whole team instantly knowing how the code works when they see it lol

I will say though if a jr dev came upon the last code they would just look it up and learn something so that’s a total valid path too. Just depends on your codebase and how your team works. I think it usually ends up being a mix with larger teams.

permalink
report
parent
reply
7 points

There’s more to it imho. The first three are more prone to mistakes than the last. You are much less likely to accidentally alter the logic intended in a simple null coalesce than you are in if statements.

permalink
report
parent
reply
0 points

That’s fair but if you had proper test coverage there wouldn’t be much risk. Who has that though? Lol

permalink
report
parent
reply
0 points

Yeah, I think there is a tipping point between terse and magic. I might grimace a little at the first one, have no comment on the middle two, and definitely comment on the last one. Wrote code like the person troubleshooting it is on-call, mildly hung over, and it’s 3am.

permalink
report
parent
reply
1 point

Yes! Please be declaritive for the next people in line!

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

  • 4.4K

    Monthly active users

  • 1.5K

    Posts

  • 35K

    Comments