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

Programmer Humor

26860 readers
2460 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
[–] andyburke@fedia.io 21 points 6 days ago (1 children)

Old programmers shouting at clouds.

(Old programmer here, I just shout at differently shaped clouds than this one.)

Edit: I am not sure if the respondents to this comment think I have a horse in this race. I said I don't and that I shout at different clouds. I am just here answering a question.

[–] floofloof@lemmy.ca 23 points 6 days ago* (last edited 6 days ago) (2 children)

Another old programmer here, and I don't see the issue. C# gets better with every release and the null coalescing assignment operator is very handy. It also exists in JavaScript.

[–] victorz@lemmy.world 4 points 5 days ago (1 children)

I feel like it boils down to understanding that operator. I'm a TypeScript developer by trade so I had no issue understanding this. 🤷‍♂️

[–] GreenMartian@lemmy.dbzer0.com 1 points 5 days ago (1 children)

For the uninitiated readers: the lead architect of C# was heavily involved in the creation of TS.

[–] victorz@lemmy.world 1 points 5 days ago

That makes a lot of sense considering the similarities between them 😊

[–] LeFrog@discuss.tchncs.de 4 points 6 days ago* (last edited 6 days ago) (1 children)

Ruby has it as well:

a ||= b

# which means
a = a || b
# wich is the same as
a = b if !a
# which rubyists like to write as
a = b unless a
# or as ternary
a = a ? a : b
[–] victorz@lemmy.world 1 points 5 days ago (1 children)

That's way too many ways of doing the same thing, yuck.

But you're saying the idiomatic way is to use unless, rather than the actual operator for this?

[–] LeFrog@discuss.tchncs.de 1 points 5 days ago (1 children)

This is basically one of the core ideas of Ruby: that you can read it like a story. Once you are used to reading it as "do X unless Y", you will miss it in other languages. Note that I wrote Y, not Y is true. Because often Y is a statement that has meaning in itself.

Example:

# imagine that given_name is some text from user input

# this is of course valid:
user.name = given_name if !user.is_locked

# but this reads more fluently:
user.name = given_name unless user.is_locked

Ruby also allows using ? as last character in method names, which is a convention for methods that return either true or false.

Same goes for ! (the bang operator), that is commonly used to tell developers that there exists a non-bang version of the same method as well. The bang method is often the more strict version (e.g. raises an error instead of returning nil; or having side effects compared to the non-bang version).

So the above example may be more commonly written like this:

user.name = given_name unless user.locked?

and the question mark makes you automatically adding is or has while reading: Set the user's name to the given_name unless the user is locked

Of course this is all by convention and you may also do it different. But that's how most Ruby code is written.

To stay consistent, lots of projects use RuboCop, which warns you on inconsistency based on your project's settings.

[–] victorz@lemmy.world 1 points 5 days ago

you will miss it in other languages

I honestly don't like the "unless X" paradigm, because it adds the condition at the end. The ??= operator shows us what will happen much sooner.

I guess it's a matter of personal taste.