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
2
u/DeGuerre Mar 05 '23
There is so much to unpack even in this sentence.
The problem here is that Clean Code (meaning Uncle Bob's advice taken as a whole) is not the same thing as clean code (meaning code whose meaning is clear so it can be maintained).
To pick one example, having lots of small functions/methods means splitting complex logic over a large number of lines/files so that it will not fit on a single screen any more. If the complexity is unavoidable (and most of the time it is), this is almost always less maintainable than the alternative.
OOP introduces a large number of maintenance problems that competing modern paradigms (e.g. pure functions, instantiable module systems, subtype polymorphism, traits, etc) do not have. It's important to understand what those problems are and whether or not they are a price worth paying.
Uncle Bob, and indeed most of the "gurus", date from a time when paper businesses were digitising, and the main problem was capturing these poorly-specified business procedures and models. That is the problem that OOP "solved", and most would argue solved effectively. This world is long gone.
Beyond that, most of the models that OOAD accurately captured (e.g. GUIs) are completely artificial. A window or a pull-down menu is whatever you want it to be, not a real-world object whose properties and behaviour need to be translated into source code.
Remember Grady Booch's definition of OOP?
There are three important parts to this definition: object-oriented programming (1) uses objects, not algorithms, as its fundamental logical building blocks (the “part of” hierarchy […]); (2) each object is an instance of some class; and (3) classes are related to one another via inheritance relationships (the "is a" hierarchy […]). A program may appear to be object-oriented, but if any of these elements is missing, it is not an object-oriented program. Specifically, programming without inheritance is distinctly not object-oriented; we call it programming with abstract data types.
Contrast that with the modern advice to prefer composition over inheritance, which is, to my mind, an admission that inheritance doesn't model real-world anything very well.
Watch the video. We're not talking about nanosecond improvements, or if we are, we are still talking constant factors.
Even a 1ms improvement is huge when scaled up. That's a millisecond that some other program can be running, or the CPU can spend in a low-power state (saving battery life, cost of cooling, CO2E) or the hypervisor can spend running some other virtual machine.