Skip to content
Tech News
← Back to articles

"Clean" Code, Horrible Performance (2023)

read original more articles
Why This Matters

This article highlights the often-overlooked performance costs associated with strict adherence to 'clean' code principles. While clean code improves readability and maintainability, blindly following these rules can lead to significant runtime inefficiencies, impacting both developers and end-users. Recognizing the balance between clean design and performance is crucial for optimizing software in the tech industry.

Key Takeaways

This is a free bonus video from the Performance-Aware Programming series. It shows the real-world performance costs of following “clean code” guidelines. For more information about the course, please see the About page or the Table of Contents.

A lightly-edited transcript of the video appears below.

Some of the most-often repeated programming advice, especially to beginner programmers, is that they should be writing “clean” code. That moniker is accompanied by a long list of rules that tell you what you should do in order for your code to be “clean”.

A large portion of these rules don't actually affect the runtime of the code that you write. These sorts of rules cannot be objectively assessed, and we don't necessarily have to because they're fairly arbitrary at that point. However, several “clean” code rules — some of the ones most emphatically stressed — are things we can objectively measure because they do affect the runtime behavior of the code.

If you look at a “clean” code summary and pull out the rules that actually affect the structure of your code, you get:

Prefer polymorphism to “if/else” and “switch”

Code should not know about the internals of objects it’s working with

Functions should be small

Functions should do one thing

“DRY” - Don’t Repeat Yourself

... continue reading