this post was submitted on 07 Oct 2025
174 points (91.4% liked)
Programmer Humor
28070 readers
1116 users here now
Welcome to Programmer Humor!
This is a place where you can post jokes, memes, humor, etc. related to programming!
For sharing awful code theres also Programming Horror.
Rules
- Keep content in english
- No advertisements
- Posts must be related to programming or programmer topics
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Well, I did have the older version on the left as a kind of rosetta stone for this. Plus, this kind of "init and/or return" pattern shows up a bunch of places, so it makes sense someone would want a quick version that's harder to screw up or has fewer side-effects.
I've also spent years investigating better ways to do things through various versions of C++, D, Rust, Go, and TypeScript. After a while, the big-picture patterns start to emerge and you see different camps start to converge on the same kinds of things. Stuff like these weird features start to feel like learning a new slang term for something you've felt, but could never say so succinctly.
In the case of
??=it's a more formalized Pythonx = x or yorx = x || yin JavaScript. The catch is that not all languages treat assignments like expressions that can be returned, so you get a clunkyreturnas a separate statement;return (x = x or y)doesn't always fly. That friction is all over the place, and it's natural to want a shorthand for this very thing.Sure enough, after searching a bit,
??=shows up in JS, PHP, and even Ruby has a version.Edit: more context.