Clean Code Is Slow, but You Need It Anyway

<p>In case you haven&rsquo;t heard, something really interesting is happening in the programming/software development scene on Twitter. It started from one of Casey Muratori&rsquo;s videos on Performance Aware Programming. It is aptly titled: &ldquo;Clean Code, Horrible Performance.&rdquo; It stemmed from Casey&rsquo;s own criticism of modern software that runs at less than 1/20 of efficiency. This is a valid concern considering inefficiencies are the reason we can&rsquo;t get nice things (and also the reason John Carmack left Meta). Then Uncle Bob (i.e., Robert C. Martin) chimed in and had a very thorough and educational&nbsp;discussion with Casey&nbsp;using GitHub. The discussion is still going on as of this day. It also spawned&nbsp;a thread in Hacker News.</p> <h1>Clean Code Is Indeed Slow</h1> <p>I have seen the&nbsp;video, and I think, although he is correct, he wasn&rsquo;t really painting the whole picture correctly. I take from his video that polymorphism and (excessive) single responsibility principle are slow (and thus, bad!), which is true, in a way. Since with polymorphism, there are costs for vtable lookup and indirections. Not to mention it will make the function and/or data scattered around and not near each other, so it will cause an L1 / L2 CPU cache miss. The same as SRPs. Extracting a function into multiple private helper functions might also cause cache misses. So do inline functions. Unfortunately, polymorphism is the heart of the SOLID principle&mdash;one of the key principles of clean code.</p> <h1>Performance Is Indeed Important</h1> <p>Efficiency and performance are pretty crucial in performance-critical software like games or embedded systems since no one would want to buy a 10 FPS game or a slow embedded device. They might also be important for backends to server content as fast as possible.</p> <p>An inefficient app, for instance, will make your device slow and hot and consume more energy than it should. For the backend, it might add to the costs of cores and/or memories or additional services. I&rsquo;d reckon this will be something to think about in the future since startups can&rsquo;t really spend more than they should. The operational cost will be smaller if you can make efficient code.</p> <p><a href="https://betterprogramming.pub/clean-code-is-slow-but-you-still-need-it-anyway-ffcac6973c93">Website</a></p> <p>&nbsp;</p> <p>&nbsp;</p>