Thoughts on Refactoring
I often find myself wanting to refactor code all the time. I sometimes look at code I have written and wish it was different. But there needs to be a reason to refactor. Beautiful code is great, but only developers are going to care. So I decided to think more about the best way to refactor. I think it is important to start with the smallest bits possible. Here is a list of some things to do that are easy.
- Remove unused parameters that are passed into methods. Maybe they were used at one time but aren’t anymore.
- Reduce the API on classes. Make protected methods private. Make public methods protected.
- Split up large methods into smaller methods.
- Try to identifier
reusable chunks to abstract into utility functions.
- Stay away from large refactors,
keep it focused on small bits.
- Make concrete methods static when possible.
By completing the small changes, it will open the way to make larger refactors possible, although at that point those refactors will turn out to not be so large and maybe unnecessary. One of the primary goals should be readability for people who are new to Zurmo. I think that is an important factor when considering if the engineering has been successful. Refactoring would be a real pain without a nice set of tests. So good thing we have that covered.