Is it ok to replace optimized code with readable code?
- by Coder
Sometimes you run into a situation where you have to extend/improve an existing code. You see that the old code is very lean, but it's also difficult to extend, and takes time to read.
Is it a good idea to replace it with modern code?
Some time ago I liked the lean approach, but now, it seems to me that it's better to sacrifice a lot of optimizations in favor of higher abstractions, better interfaces and more readable, extendable code.
The compilers seem to be getting better as well, so things like struct abc = {} are silently turned into memsets, shared_ptrs are pretty much producing the same code as raw pointer twiddling, templates are working super good because they produce super lean code, and so on.
But still, sometimes you see stack based arrays and old C functions with some obscure logic, and usually they are not on the critical path.
Is it good idea to change such code if you have to touch a small piece of it either way?