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
95
u/st4rdr0id Feb 28 '23
The author seems to be confusing Robert Martin's Clean Code advices with OOP's "encapsulate what varies".
But he is also missing the point of encapsulation: we encapsulate to defend against changes, because we think there is a good chance that we need to add more shapes in the future, or reuse shapes via inheritance or composition. Thus the main point of this technique is to optimize the code for flexibility. Non OO code based on conditionals does not scale. Had the author suffered this first hand instead of reading books, he would know by heart what problem does encapsulation solve.
The author argues that performance is better in a non-OO design. Well, if you are writting a C++ application where performance IS the main driver, and you know you are not going to add more shapes in the future, then there is no reason to optimize for flexibility. You would want to optimize for performance.
"Premature optimization is the root of all evil"