Thursday, August 06, 2009

Refactoring: Means versus Ends

First, I see 2 reasons to refactor:
  • Improve performance
  • Make code easier to maintain (and extend)
Most other "reasons" that people use to justify refactoring are only a means to one of the 2 ends stated above. If you aren't ultimately reaching one of those ends, then reconsider refactoring. If your changes are to the detriment of one of these 2 means, then don't refactor. In fact cargo cult refactoring can be more harmful than helpful.

Think about these:
  1. Not all duplication is bad. Some blocks of code are more self explanatory then an oddly named method that wraps it. Saving 6 lines of code may come at the cost of flexibility and higher levels of coupling.
  2. Overly abstract code can become highly unmaintainable, even cryptic. In an effort to write more concise code we inadvertently write less concise code. Specialization can be a good thing. Astronaut APIs can be bad.
  3. and of course...premature optimization is the root of all evil!
Just a few things to think about...

2 comments:

salma said...


شركة اصباغ الكويت اصباغ الكويت
شراء اثاث مستعمل الكويت شركة شراء اثاث مستعمل الكويت
فني كهربائي منازل الكويت كهربائي منازل بالكويت
شركة مكافحة البق الكويت افضل شركة مكافحة البق الكويت
شركة مكافحة حشرات الكويت افضل شركة مكافحة الحشرات الكويت
نقل عفش مبارك الكبير شركة نقل عفش مبارك الكبير


Anonymous said...

This was a fun and approachable read, making a complex topic easy to understand. https://www.sidingcoquitlambc.com