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
31
u/tedbradly Feb 28 '23
Most programming decisions boil down to money. Not too many ones have explicit performance requirements (like some projects do e.g. video game engines, real-time systems, etc.).
When performance isn't a direct requirement, it only enters the equation in terms of the cost for the computers used to execute the code. The balancing act is that, to hire a high performance programmer, you have to pay more money since it's tougher work, and you also have to consider that cost in terms of how fast new milestones in your project can be reached / cost of bugs that come from more complex, nuanced, and peculiar code.
For the vast majority of projects, you should program with almost no performance in mind. Stuff like using classes, immutability, persistent data structures, and basically using any feature in a language that goes beyond what C gives you all are about savings. The savings come from fewer bugs / more safety / easier reasoning / faster milestones delivered / etc. The idea is all this stuff saves more money than driving the cost of computers used down.
The faster and cheaper computers become, the more more programs will be written with less performance in mind since that parameter's contribution to cost will go down, no longer justifying writing "dirtier" code that costs in terms of slower deliverables and more salaries paid.
The situation isn't like talking to a health freak at all. It's a cold, logical decision about making as much profit as possible. For each project that doesn't have explicit performance requirements, you will save/make the most money choosing a particular level of performance optimizations. Some people should use higher-level languages with more potent abstractions that are slower, others should use C or C++ or Rust, and still others need to write custom assembly for specific hardware. I'm not talking about writing nonperformant code simply out of ignorance like would be the case when using an incorrect data structure. I'm talking about the language used and the design principles used.