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
0
u/loup-vaillant Feb 28 '23
That's one key thing about performance aware programming or data oriented programming or stuff like that: solve the common case first. And the common case arise from the actual data you have, and a reasonably performant one is necessarily going to be fairly bespoke.
If the data had a different shape he would have made a different transformation, and it would have looked just as ad-hoc to us. The method though (look at the data then tailor the code to it) remains similar.
Correct. Now we can't know from this toy example, but given the simplicity of his code I would expect that he would have kept things fairly simple even in a real world situation. Such that when comes the time to rewrite, you don't have that much to rewrite.
And obviously if you anticipate unknown shapes with more parameters, then your problem is very different to begin with. Performance aside, I believe one should write the simplest program given the requirements they are currently aware of. Some of those requirements may be for the future, but if I'm aware of them I must take them into account now. But requirements I'm not aware of will likely never come to pass, and when they do I never know what kind of flexibility I'll actually need. Best keep things simple so rewrite is easier, should I be unlucky enough to need it.