Three reasons why I love to refactor code

After writing some code that works, we look over it. We notice the little things that could be faster, a conditional that doesn't have to be there, logic that could be grouped and even better, code that can be deleted. We make the finishing touches and sit back and admire the fruit of our labor.

Refactoring is really a joyful activity to me. It accounts for the majority of my satisfaction when I code. A few days ago I had a sudden realization as to why I love it so much.

Refactoring is self-improvement

I love self-improvement. Especially when I can see it. When I play an instrument, there's a huge amount of satisfaction in the obvious improvements. The same applies for coding. The tidying up I do makes me feel like I just cleaned my room!

Overtime, the refactors I would do after I finish a piece of code become embedded in my first drafts. It becomes more and more apparent as you look over your code how you've grown. Am I the only that gets excited when I see good looking code?

Refactoring someone else's code (with permission) is teaching

When someone asks you to improve their code, it's a teaching opportunity. You're able to explain through action the words that are usually hard to explain. Often times, I learn more than I teach when I touch someone else's code. In the end, it's a net positive. Don't do this when not asked though, it's not a pleasant experience to see your hard work changed without warning!

Seeing my code refactored is my favourite learning experience

I love when my code is refactored. To me it's like async pair programming. I get to see how someone would solve the same problem, and since I would say that I'm not very creative, it's the inspiration I need for future similar problems.

Do you like to refactor? Let me know why!