This week I am going to over a post from the CodeGuru. The post starts by talking about the importance of refactoring, what it is and why we refactor. They define refactoring as the process of restructuring or improving the internal structure of code while keeping the functionality of the code and not changing its external behavior. The article then goes on to talk about when the pros and cons of refactoring and why sometimes it is not best to refactor.
Refactoring code can help prevent bugs but if done improperly, refactoring code can also create bugs in your code so that is why it is important to be careful when refactoring code. In the article, it talks about how it is a good habit to analyze your code before refactoring code. If after analyzing your code, you find that you have to refactor most of your code, they caution you against refactoring the program because you may end up creating more work for yourself. Instead, they recommend that it may be better to start over from scratch. Another practice they implore coders to follow is you should not refactor code if you don’t have the tests or plan to create the tests for that code. This is because, without the tests, you may not have sufficient information about whether or not your code has changed the behavior of the program. Another good practice they recommend is you should wait until you deliver the product and use the time in between tasks to refactor code. Software development can be a very time-sensitive industry so some good practices that we should have as programmers are we should be mindful of the time we have before deadlines and be able to analyze whether a task can reasonably be done in the allotted amount of time. We should also establish clear and achievable goals and refactor code in between tasks and before adding new features to the program so that we can avoid technical debt.
I chose this post to review this week because I think it is a very important topic not just in this class but in programming in general. One of the reasons why I chose this topic, in particular, is because in class we often toss the term around in class, we know what it is and how to do it, but we never really talk about how to do it well or what are some good practices that we should follow. Personally, I have been following some of these practices all along such as gauging my time before deadlines and making objectives along the way, but I also have a really bad habit of deviating from those objectives. There were so many times in my undergraduate career where right before an assignment is due, I ended up refactoring the program from start to finish or redoing the entire assignment from scratch. Now that I know good refactoring habits, I can avoid this in the future.
https://www.codeguru.com/csharp/best-practices-for-code-refactoring/
From the blog CS@Worcester – Just a Guy Passing By by Eric Nguyen and used with permission of the author. All other rights reserved by the author.