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