this post was submitted on 07 Oct 2025
170 points (91.3% liked)
Programmer Humor
26846 readers
2598 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
Man, I've successfully stayed away from C# for a few years now, but that's wild to me that the
x ??= y
operator would be intuitive to you.This could've easily been two or three operations, without being much more verbose, but actually being somewhat intuitively readable for most devs...
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 y
orx = x || y
in JavaScript. The catch is that not all languages treat assignments like expressions that can be returned, so you get a clunkyreturn
as 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.