this post was submitted on 21 Mar 2024
295 points (94.8% liked)

Programmer Humor

19623 readers
5 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] 40 points 8 months ago (29 children)

Const everything by default

If you need to mutate it, you don't, you need to refactor.

[–] ByGourou 8 points 8 months ago (1 children)

Sorry, I want to make an app that works, not a perfect art piece.

[–] [email protected] 4 points 8 months ago (1 children)

The app working isn't good enough, it needs to be maintainable. From a professional perspective, unmaintainable code is useless code.

Code that mutates everywhere is generally harder to reason about and therefore harder to maintain, so just don't do it (unless there's literally no other practical way, but genuinely these are very rare cases)

[–] ByGourou 1 points 8 months ago (1 children)

I personally disagree, forcing yourself to use non mutable variables only leads to longer and more convoluted code.

[–] [email protected] 2 points 8 months ago

Fair play, I guess we're probably just gonna disagree.

In my experience I'd say mutable code (larger than anything other than toy examples) always results in more time spent fixing bugs down the line, predominantly because it's objectively harder for humans to reason about multiple one to many relationships rather than multiple one to one relationships. I'd say because you need to think about all possible states of the set of mutable variables in your code in order to completely understand it (and I don't just mean understanding the intended purpose of the code, I mean understanding everything that code is capable of doing), that usually results in a more convoluted implementation than the pretty linear way you typically read functional code.

Longer code is practically always better if it's easier to understand than the shorter alternative. Software engineers aren't employed to play code golf, they're employed to write maintainable software. Though I'll say ultra high performance applications might be the exception here—but 99% of engineers aren't doing anything like that.

I'm always happy to be convinced otherwise, but I've never seen a convincing argument

load more comments (27 replies)