DEV Community

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

Collapse
 
rhymes profile image
rhymes

I love refactoring code, mine or other people's. It helps me learn something new and figuring out how it actually works or how it can be improved.

Just don't get carried away into refactoring everything.

Choose an inital goal, maybe a small one. Yeah this or that module could be better but:

  • are you refactoring to lower the technical debt?
  • are you refactoring just for the sake of refactoring?
  • are you refactoring to make way for new features?

I agree with @kuhnerdm , you should write a few tests of your own, especially if there's neither documentation nor comments.

Keep in mind that refactoring can introduce bugs, especially if there are no tests :D

Collapse
 
samsha1 profile image
samsha1

Hey, @rhymes thanks. Now, I am clear that tests are key things to start with as mentioned by many.

Collapse
 
rhymes profile image
rhymes • Edited

I forgot to mention this: I would begin with functional/integration tests first, unit tests later or at least I would de-prioritize them.

If there are no tests you should start testing for features, not necessarily for small units.

Play with the actual app, understand how it works, maybe sprinkle it with some log.debug statements if you're unsure, then write a test where you "excercise" a behavior and expect an output. If you do this a few times you setup a battery of tests tied to specific functionalities.

After that you can refactor with a little safety net in the form of those tests that can also act as a documentation for posterity.