this post was submitted on 02 Oct 2024
606 points (96.3% liked)

Programmer Humor

19488 readers
1062 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 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] -5 points 1 month ago (17 children)

Alright, spicy opinion time: I think, the ! operator is dumb.

It's yet another symbol with a meaning, which people have to learn.

And it's easy to overlook, especially in languages with parentheses in their if-conditions:

if (!list.isEmpty()) { ... }

I think that just a .not() method on Booleans is cooler:

if (list.isEmpty().not()) { ... }

You can do this in Rust, which is where I have that idea from: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=dedb71bd84243c78ee0afad0f30b80c3

[–] [email protected] 19 points 1 month ago* (last edited 1 month ago) (1 children)

I dislike the .not() method a bit because it inverts the meaning of the previous code snippet you've read.

if (list.isEmpty()...

"Ah, so if the list is empty..."

if (list.isEmpty().not())

"Goddammit"

[–] [email protected] 7 points 1 month ago

For me, it's pretty much the opposite. With the exclamation mark, I'll see the inversion, then I'll read the actual condition and try to make sense of it, and then I'll remember that this thing was supposed to be inverted. Or I won't remember, that's unfortunately also a possibility.

Might just be what we're used to, though. I have been working in a codebase with mostly .not() for the past year.

load more comments (15 replies)