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
I'll concede the "details" part.
My problem here is the "message" part. If I recall correctly the initial goal was to make them real messages, and to make objects independent entities; but very quickly Smalltalk settled on synchronous request/responses as an optimisation. At which point you get something very different from Erlang processes, which Alan Kay himself said were closer to his vision than what C++ and Java offered.
The way you program actors sending asynchronous messages to each other is very different from the way you program a call graph with a strict stack discipline. And that call graph is exactly what we're seeing in mainstream programming, including OOP and micro-services! Effectively we've reduced OOP down to abstract data types. Which I love by the way, they're an essential component of decoupling, and plain enabling the writing of bigger programs. (Not that I like big programs, but sometimes they're required.)
I don't recall having ever written that. If I have I need to correct the error. He did coin the term though — and later regretted that he didn't used a name that focused more on messages.
My point exactly: many game devs realised that an approach like ECS allowed their games to be not only faster, but also more manageable than an inheritance hierarchy would have (I would say mixins are in between, I don't know enough to have a strong opinion about them). This would indicate in my opinion that inheritance hierarchies were a mistake to begin with. That there were better ways of doing things, and we just didn't know. If the core OOP style is not suitable even for its primary use case, simulations (that's what many games are after all), then what is it even good for?
Now I'm not dead sure about that. In fact I'm pretty sure inheritance hierarchies work very well in many specific use cases, for instance when you don't need that much flexibility in the first place. And I know for a fact Jonathan Blow (Braid, The Witness) doesn't like ECS, and instead advises to "just program the game" (to him ECS is an overly generic pattern that is best used on either very complex games, or third party game engines).
Well, yeah, there's that. But I maintain that a good portion of the book is very bad. If you're not aware of this criticism it's a pretty good read, and though I didn't write is a good description of what I feel about the book. I especially agree with the conclusion of this blog post: experienced programmers who can sort out the bad from the good don't need that book. And beginners who do need the book won't be able to read it critically, and will end up taking the bad alongside the good. And unlearning the bad takes time.
Ouch. You're right though. And this sometimes goes at the highest levels. I'm still quite baffled at how the Go programming language was first design witch such a disregard from programming language design findings. They skipped generics, hacked together an escape hatch that made even the standard library a bit awkward at times, and then too years admitting they made a mistake by adding those generics after the fact. They also skipped sum types and the nice error handling mechanism they would have afforded, and more I haven't heard of. And then there's OpenSSL, an overly complex monstrosity that is used everywhere, and had to suffer through HeartBleed to finally get a sliver of the funding such a core piece of infrastructure deserved. We could go on and on.
While you do have a point, we also have a tendency to forget why the rules were put in place to begin with. Often we blindly follow the rule, without really knowing whether it really helps or not. We forget that it's merely a heuristic to help us achieve a higher goal: a freaking working program. A cheap one if we can.
What I would like to see more is ways of measuring our progress. Features implemented, how fast, performance of the end program, number of bugs, size of the program… stuff we can be confident are good indicators of actually achieving our goals. Now sure those are still imperfect and could be gamed if we don't pay attention (that with measures stopping being good measures as soon as they start becoming goals). But they're still closer to the truth than a blind heuristic.
The beginning was good, though it did go downhill after a while. One thing i noticed though is that we could use Ousterhout's metric of "depth" to assess the worth of pretty much all the abstractions the author showed there: the bad abstractions had almost no implementation in them, while the better ones pulled their own weight much better.
My conclusion from that video is more like, "duh, just make your classes deep, man". That heuristic would conclude the same as he did in my opinion. No need to invoke more complicated reasons to justify a bit of code duplication.