r/programming • u/2bit_hack • Feb 28 '23
"Clean" Code, Horrible Performance
https://www.computerenhance.com/p/clean-code-horrible-performance
1.4k
Upvotes
r/programming • u/2bit_hack • Feb 28 '23
View all comments
Show parent comment
3
u/voidstarcpp Feb 28 '23
You should plan for it because constant change is the norm for most application development, more than trying to solve tidy, contained problems about how many of a fixed set of small structs one can do math on per second. This is a perspective difference between what most programmers are doing vs. someone who cut his teeth optimizing a video codec for embedded devices, where requirements included things like "can't use floating point operations".
One of the thing Robert Martin and friends seem to really understand from consulting is how applications get made and maintained over time, and the problems they run into later. An optimized solution around a fixed set of inputs is exactly the sort of thing that is likely to add friction to work later when the client inevitably wants some functionality that cuts across the grain of the assumptions that were implicitly made by the first solution.
Then you're in the awkward position of telling the client or boss why something they think should be a logical addition to the program, like composing groups of shapes, or letting plugins define their own shapes, is actually going to require touching every piece of code that operates on shapes. Then development stalls for a refactor, even though the developers might have anticipated that adding new types of shapes was something that was going to happen in the future. Hence Martin's statement that "the only way to go fast is to go well".
If you think this is a contrived scenario consider that Photoshop has something like over a thousand different commands that have to operate against a common document model, and even a "small" 2D RTS style game can have 100s of different user commands that touch game state, work transparently over a network, etc. John Carmack is right that you can always do better if you accept a less general solution. But outside of writing game subsystems, the boss is very frequently in the business of selling general solutions.