this post was submitted on 07 Oct 2025
171 points (91.3% liked)

Programmer Humor

26891 readers
458 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

founded 2 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] UnderpantsWeevil@lemmy.world 114 points 1 week ago (23 children)

When you're an old-head who recognizes the old style it is easy to read the old style.

When you're a new-head who recognizes the new style it is easy to read the new style.

When you've never seen C# before, they're both gibberish.

When you've got experience with both, it can get a little confusing but you'll catch on without too much difficulty.

But its fucking wild to think the left side is more readable than the right side, simply because it is more verbose.

[–] dejected_warp_core@lemmy.world 14 points 1 week ago (9 children)

Eh, I haven't touched C# since 2001. I agree that the more verbose style is more explicit, and so more readable. That said, I can figure most of the new style out from context.

  • => is clearly a closure declaration operator, similar to JavaScript.
  • x ??= y is shorthand for "assign y to x if x is not set, and return x" which is kind of nice.

There must also be some shorthand going on for getter properties being the same as methods w/o an arglist (or even a ()).

The only part that has me stumped is the unary question-mark operator: private static Singleton? _instance = null; I can think of a half-dozen things that could be, but I cannot decide what it's doing that the original question-mark-free version isn't.

[–] sidelove@lemmy.world 2 points 1 week ago

The only thing that's not obvious to me is that ??= doesn't seem to invoke new Singleton() if it's already defined, essentially short-circuiting. Otherwise I would have to look up the semantics of it if I were worried about that constructor having side effects or doing something heavy.

load more comments (8 replies)
load more comments (21 replies)