DEV Community

Discussion on: How it's like to refactor code, written by other developer?

Collapse
 
ben profile image
Ben Halpern

Oooh this is a juicy topic.

I think key to both understanding of the code and confidence in changes: Tests!

You're in luck if there are tests.

If you don't have tests, you still may want to start attempting to write tests to get your head on straight about the way the code works.

If it's not practical to write tests, I think it really becomes a matter of poking and prodding and learning about the behavior, and start making some small local refactors as you work your way into a better idea of the whole code base. You definitely want to be cautious and defensive in this process.

Collapse
 
derekjhopper profile image
Derek Hopper

Uncle Bob had a recent Twitter thread about this too: twitter.com/unclebobmartin/status/...

If you have no idea how the code works, poking and prodding seems like the best place to start. Once you start to reason about the flow and understand things enough, start adding tests. Basically, do whatever it takes to get the code under test.

You definitely want to be cautious and defensive in this process.

If you have time to read or study, the book Working Effectively with Legacy Code might give you some ideas on how to be defensive.

Collapse
 
ben profile image
Ben Halpern

Yeah, this is definitely territory where UncleBobeology shines.

Collapse
 
bosepchuk profile image
Blaine Osepchuk

+1 for Working Effectively with Legacy Code - excellent book!

Collapse
 
samsha1 profile image
samsha1

Thanks @ben . Yes, I have started writing some test code but needs lots of patience really!!

Collapse
 
ben profile image
Ben Halpern

On this general topic, I really like this post from the current DEV homepage: