DEV Community


Posted on

Guides to Refactoring

One of the things I am lacking in experience with is refactoring code. So I did what I always do, and asked Twitter for their thoughts.

I picked out a few things from the replies I intend to go through and added some of my own. I cannot vouch for any of these yet, so do let me know what you think of them.

  1. šŸ“™ Paid: 99 Bootles of OOP by Sandi Metz
  2. šŸ“™ Free: Refactoring JavaScript
  3. šŸ“™ Paid: Refactoring by Martin Fowler
  4. šŸ“™ Insight Loop: Code by Refactoring, a workshop by Deep Roots
  5. šŸ“ŗ Therapeutic Refactoring by Katrina Owen
  6. šŸ“ŗ Refactoring from Good to Great by Ben Orenstein

A book is never going to teach you something fully though, everything you learn needs to be put into practice. So, find some small pieces of the codebase you're most familiar with and ask yourself if it could use some cleanup. Maybe there's a Class that's 700 lines long? Or a React component that has turned into an absolute monster? šŸ§Ÿā€ā™‚ļø

I'm curious if you have any other resources or tips on the art of refactoring, so do share in the comments!

Top comments (6)

katnel20 profile image
Katie Nelson

I find myself refactoring in chunks. When I read someone else's code like at GitHub, I see something there and think I didn't know there was a library or function for that! Then I start refactoring small pieces of my code which sometimes leads to a major rewrite.

Thanks to your list, I will read up on a better way of handling it.

Hi to Peanut.

murrayvarey profile image

Therapeutic Refactoring -- Awesome title, will have to give that a watch.

I'd recommend Practical Refactoring by LLewellyn Falco and Woody Zuill. The format's nothing special -- just two guys giving a workshop -- but I took a lot from it.

nicoespeon profile image
Nicolas Carlo

Thank you for this list! I'll bookmark it so I can share a handy recap šŸ‘

As a recommendation, I've been using a lot. Content is very similar to Fowler's awesome book and it has nice illustrations to explain concepts.

Finally, if you're a VS Code user and do JS/TS, you'll be interested in the Abracadabra extension. It provides helpful, intuitive automated refactorings. I'm the author so don't hesitate to tell me your feedback is you try it out šŸ˜ƒ

anwar_nairi profile image

Thanks for gathering those resources James šŸ¤“

I do not refractor a lot, while I still maintain a PHP 5.6 hand made app. When I do refractor, I notice the time I will spend on is definitively related to the quality of the code I am maintaining. If the previous developer mind was clear, the code will be, and the refractor will make a lot of sense while not being hard to walk through the code. Just my feeling about it.

varjmes profile image

That makes sense! Refactoring can also come when the code is good, but you want to upgrade to more modern techniques. For example, converting from ES5 to ES6 JavaScript. Of course, you should't refactor if you don't have a good reason to!