Is it ok to replace optimized code with readable code?

Posted by Coder on Programmers See other posts from Programmers or by Coder
Published on 2012-06-11T16:20:47Z Indexed on 2012/06/11 16:47 UTC
Read the original article Hit count: 386

Filed under:
|
|
|

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?

© Programmers or respective owner

Related posts about c++

Related posts about c