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.
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.
I'm a small business programmer. I love solving tough problems with Python and PHP. If you like what you're seeing, you should probably follow me here on dev.to and then checkout my blog.
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.
Avoid the Code Crawl by Reading Tests
Brandon Martinez
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.
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.
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.
Yeah, this is definitely territory where UncleBobeology shines.
+1 for Working Effectively with Legacy Code - excellent book!
Thanks @ben . Yes, I have started writing some test code but needs lots of patience really!!
On this general topic, I really like this post from the current DEV homepage:
Why do great developers love writing tests?
anabella