These days Add-ins are all about code refactoring. What is “code refactoring” and can they bring benefits to your work?
"A code refactoring is any change to a computer program's code which improves its readability or simplifies its structure without changing its results"
Source: Refactoring
What you need to keep in mind is that “Code Refactoring” is useless without existing codes. So that means if you are not going to bother about existing projects that are dusting some where in one of your folders then “Code Refactoring” is not for you unless you have the habit of writing bad codes that you need to refactor your codes as you go along.
In software development there are techniques that can be applied to improve code structure, readability, and maintainability. I won’t be able to cover them all in one post. In my early days in software development I discovered about the encapsulation technique, the old name for Code Refactoring.
The encapsulation technique is very easy to learn. All you have to do not to rush that code to make it to work and once it does forget all about it how actually you could have improved it. Software developers would never go back to the code they write unless there is a bug or have to change it to support the new logic.
I can think of numerous occasions where I spent only few minutes more on the routine that I was working on and in return it saved me hours of work later on.
In encapsulation technique you would divide the algorithm into sub-routines where each sub-routine can be modified at later time to handle more logics without breaking the entire logic and also you would allow the same sub-routines to be used by other layers or services in your application without repeating the same logic again.
If you are writing a method/function that has a large algorithm (routines) be assured there is something wrong with your approach in solving the problem. One of the hardest things in software development is to keep the solution simple. This is something you can master only by learning from your past mistakes.
Software development is far more than learning about the language specific syntaxes, hacking the API, and how to google the algorithm you need. The bottom line is that if you are not already familiar with some of the techniques in software development then you wouldn’t know how beneficial code refactoring is.
If you are an experienced developer less likely you would benefit from the massive refactoring features are being offered by various vendors. This is because you would code from the beginning in the same manner these code refactoring features offer.
The market currently is focusing on “Code Refactoring” techniques to help the software developers on their daily tasks. I personally feel professional developers are left behind as I don’t believe all “Code Refactoring” techniques are beneficial to them as they know how to code an already refactored code from the start.
The “Code Refactoring” can be divided into two main categories;
-
Code Enhancements
-
Pure Productivity
A good example for “Code Enhancements” category would be the Visual Studio’s built-in “Extract Method” refactor command. A good example for Productivity would be the Visual Studio’s built-in “Extract Interface” refactor command.
What is the difference between the two you might ask?
To answer this question fairly it would be better to talk about the benefits a command such as “Extract Interface” brings then you can compare the two by yourself. As you already know this command can extract members from existing types and creates a new interface from them. The obvious usage of this command is when at one point you decide to derive existing types from an interface. On the other hand, the not so obvious benefit is how you can work when you have such command at your disposal. Let me elaborate more on that if you will.
When you are designing a class that you would know in advance it derives from an interface most likely you would design the interface first and then the derived type second. The chances you get everything right first time are very small therefore any changes to the members of either object templates need to be synchronised between the two.
To increase your productivity you can design your actual type first without worrying about the interface part then once you are happy with the initial testing and design then within seconds you can create the interface. In this way you have saved yourself from working with two object templates at lesser time.
Tools are made because there were demands for them. You need to look at your own needs to see what tools would fit to your requirements best with the available budget.
There isn’t a perfect tool out there unless it does one thing only. Stop looking for that perfect tool, look for the tool that would have the most benefits for you.