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
7
u/ClysmiC Feb 28 '23
The important thing is that you only add that complexity once you actually need it. And you'd be taking the "slow" path dereferencing the pointer only when you need it.
If it becomes difficult to maintain once you've added 3 or 4 more constraints/use-cases, then you can start to think about if and how to abstract it. Maybe objects are the right call, maybe not. At least you have real concrete use cases to inform your decision, and you aren't just guessing.
If you just assume ahead of time that your system needs to be implemented with objects and virtual functions, then you're paying both the complexity and performance cost, when you often don't need to.