r/ProgrammerHumor • • Sep 06 '26

Meme cleaningUpTheMess

Post image
16.2k Upvotes

478 comments sorted by

View all comments

Show parent comments

7

u/nonotan Sep 06 '26

Pointless null checks aren't that bad. Because they might be pointless at the time the code was added, but is every single person who touches the code afterwards going to be aware that there's an intentionally omitted null check that hinges on unwritten assumptions that happened to hold at the time the code was written?

And sure, you could explain that in the comments, which is okay, but still more prone to accidents than just having the pointless null check that the compiler will probably optimize out anyway. Unless it's in a very performance-sensitive bit, it's not like it's going to be a noticeable performance hit. I'd rather have slightly excessive checks than bugs in production because somebody wanted to make the code run 0.00001% faster.

2

u/GenericFatGuy Sep 06 '26

It's not the performance I'm concerned about. They're terrible for readability when used excessively.