Clean Code Is Slow, but You Need It Anyway
<p>In case you haven’t heard, something really interesting is happening in the programming/software development scene on Twitter. It started from one of Casey Muratori’s videos on Performance Aware Programming. It is aptly titled: “Clean Code, Horrible Performance.” It stemmed from Casey’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’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 discussion with Casey using GitHub. The discussion is still going on as of this day. It also spawned a thread in Hacker News.</p>
<h1>Clean Code Is Indeed Slow</h1>
<p>I have seen the video, and I think, although he is correct, he wasn’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—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’d reckon this will be something to think about in the future since startups can’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> </p>
<p> </p>