2 ms·
In my experience, "mildly optimised" code tends to be simpler and more efficient in terms of the effort required to maintain it too. Anyone who has compared a c
by userbinator 10y ago
In my experience, "mildly optimised" code tends to be simpler and more efficient in terms of the effort required to maintain it too. Anyone who has compared a compiler's -O0 to its -O1 will likely come to the same conclusion. It's only at the "-O2" and above where the effort starts becoming significant.
Of course, different programmers will have different ideas of what "mildly optimised" means; what I mean by "mildly optimised" above is actually the code I'd write as a first pass and consider not optimised at all, and not "the first thing that comes to mind even if it's actually horribly stupidly inefficient" which a lot of programmers seem to do. In other words, my idea of unoptimised is probably more like a -O1, and I'd have to spend extra effort "pessimising" to go below that.
- stcredzero 10y agoThe 80/20 rule tends to give you significantly different returns on optimization, depending on what code you optimize. Then, there are other priorities to consider, like optimizing for programmer reads. By all means, if you can write easier to understand code by writing efficient code, then do so. "the first thing that comes to mind even if it's actually horribly stupidly inefficient" There are certain practices, like the "Law of Demeter" and the "Replace Temp with Query" refactoring that are deliberately inefficient for the purpose of making refactoring and code changes easier. I think of these as being somewhat like a filing system that leaves a little bit of inefficiency to facilitate later reorganization.