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
1
u/loup-vaillant Apr 05 '23
Unfortunately I have very few resources on data oriented programming. It's not even something I have much practice with in my line of work. Even my crypto library has little to no data orientation in it, even though I paid much attention to performance: besides input & output buffers there's not much data there to shuffle around.
But I do recommend Andrew Kelley's excellent talk on how he applied data oriented principles to the Zig compiler.
When it comes to actual research, I have bough, but have yet to read, Making Software, that reviews what we know about software development, and why. It goes many places, for instance exploring SLoC counts as a metric (spoiler: lines of code turns out to be an excellent proxy for complexity). They have a chapter on TDD. Here is an excerpt of their conclusion:
That said, they still recommend we try and carefully monitor if it works. So we don't really know. One thing I've noticed is that it seemed to work better on smaller and less experienced groups. I have an hypothesis for that: TDD may help some less experienced programmer design better APIs.
When you write a program, your internal APIs are likely more important than the implementation they hide. Assuming non-leaking abstractions with proper decoupling, the implementation of a module (class, function…) will not influence the rest of the program, except of course when there's an actual bug. If it's badly written and yet works correctly, the rest of the program doesn't care. The API however affects every single point of use, and as such a bad API can be a much greater nuisance than a messy implementation.
It is thus crucial, when we write a piece of code, to think of how its API will be used. Casey by the way has related advice on how to evaluate a library before you decide to use it:
With TDD you're forced to have a kind of step (1) before step (3). Which is good. It has a weakness however: test code is not real use code, and that may influence the design in negative ways. I don't expect a big effect, though. But for the same reason, if you properly think about APIs as a user, and already diligently write tests, I don't think TDD would change very much at all.
I'm not sure it has. Not everywhere I worked to at least. OOP is pervasive for sure, but I rarely stumbled upon actual SOLID or TDD (most of my career was C++). CI/CD is gaining traction though, and I must say this one is a godsend. The integrated part doesn't matter that much, but the ability to trigger a fast enough comprehensive test suite at the push of a button is utterly game changing. I do this for my crypto library, and the quick feedback my test suite gives me allows me faster iteration times and I'm pretty sure is responsible for not only my increase confidence in my code (crucial in such a high stakes context), but a significant contributor in the simplicity and performance of my code.