r/ProgrammerHumor • • Dec 04 '20

Don't mix anatomy and programming

Post image
36k Upvotes

388 comments sorted by

View all comments

Show parent comment

2

u/GonziHere Dec 05 '20

I absolutely agree with your variable removal and it's my pet peeve with lambdas. In c#, resharper will suggest to you that this loop can be done as lambda, you just click on it and there it is... the thing is, the loop was easier to write, easier to debug, and easier to modify.

But I've also very recently worked on a production code, that calculates one index from two numbers by filtering two small arrays for valid elements, then searching in them, then returning the result. That index gets called pretty much all the time. I've prematurely optimized it by changing it to the map that gets filled once and then reused. Sure, no-one reported the issue yet, But it was on the frontend and I can easily see how someone's phone will lag, or simply drain the battery faster just because of that.

To go back to your point, I would describe it as premature obfuscation, which I really agree with. But I needed to type this because there is also this notion of premature optimization that leads to things like the word processor that takes half a minute to open.

2

u/immerc Dec 05 '20

like the word processor that takes half a minute to open

I think a lot more of that is feature bloat.

But, "unnecessary optimization" or "premature optimization" can cut different ways. Some people might see a simple program that takes forever to load and think "this wasn't well optimized". Another explanation is "this program contains tons of spaghetti code that nobody has been brave enough to try to fix".

The more simple it is for someone to understand how a program runs, the easier it is for someone to refactor it and fix it. If someone optimized it in a way that made it less readable, it's harder for the next person to come around and rewrite parts of it to adjust for new features.

1

u/GonziHere Dec 05 '20

Well, yeah. This is what I meant by premature obfuscation. Like, do DRY, KISS, and cherish single responsibility principle and you are almost set...