DEV Community

james
james

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.

https://twitter.com/varjmes/status/1189574679142588417

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 (5)

Collapse
 
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.

Collapse
 
murrayvarey profile image
MurrayVarey

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.

Collapse
 
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 refactoring.guru/ 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 πŸ˜ƒ

Collapse
 
anwar_nairi profile image
Anwar

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.

Collapse
 
varjmes profile image
james

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!