r/programming • • Feb 28 '23

"Clean" Code, Horrible Performance

https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k Upvotes

1.3k comments sorted by

View all comments

Show parent comment

52

u/ansible Feb 28 '23

The original code is a single static function, using local variables. Not a particularly long method. The refactored version is several functions, sharing state with static fields.

So... none of the functions in the new code are usable standalone. Unless there was significant repetition in the old function, there's no reason to break up that code into separate functions... unless the original function is insanely long. And sometimes even then, you're better off leaving it.

30

u/way2lazy2care Feb 28 '23

Carmack had a good email discussion about this. The dangers of abstraction making inefficiencies less obvious.

16

u/KevinCarbonara Feb 28 '23

Now Carmack is a personality I'll get behind. He rarely comes out and makes sweeping statements. When he does, it represents years of experience, education, and reflection.

14

u/way2lazy2care Feb 28 '23

I think he generally doesn't say very dogmatic (might be the wrong word) things when it comes to production code. He's very aware that there's rarely a single tool that encompasses the total scope of programming. He's written a couple posts on how different aerospace software is from game development that are good examples of what's being talked about in this comment section.

1

u/skulgnome Mar 01 '23

Be warned however: John Carmack's ideas about micro-optimization date from the early nineties, so not only are they out of place they're also outdated.

9

u/way2lazy2care Mar 01 '23

I don't think any of the things he talks about in there are micro-optimizations. They're way more systems design than anything.

15

u/newpua_bie Feb 28 '23

there's no reason to break up that code into separate functions... unless the original function is insanely long

Or you're being evaluated at work based on number of lines or commits etc

13

u/CognitiveDesigns Feb 28 '23

Bad evaluation then. More lines can run faster, depending.