Skip to main content
Source Link

The answer is, without loss of generality, yes. Always add modern code when you see hard to read code, and delete the bad code in most cases. I use the following process:

  1. Look for the performance test and supporting profiling information. If there is no performance test, then what can be asserted without evidence can be dismissed without evidence. Assert that your modern code is faster and remove the old code. If anyone argues (even yourself) ask them to write the profiling code to prove which is faster.
  2. If the profiling code exists, write the modern code anyway. Name it something like <function>_clean(). Then, "race" your code against the bad code. If your code is better, remove the old code.
  3. If the old code is faster, leave your modern code in there anyway. It serves as good documentation for what the other code is meant to do, and since the "race" code is there, you can keep running it for documenting the performance characteristics and differences between the two paths. You can also unit test for differences in code behaviour. Importantly, the modern code will beat the "optimised" code one day, guaranteed. You can then remove the bad code.

QED.

Post Made Community Wiki by Sunny Kalsi