Code refactoring is must have skills in our tool box.
Wikipedia gives below mentioned definition
Code refactoring is the process of restructuring existing computer code without changing its external behavior.
There is a classic book on Refactoring by Martin Fowler.
The topic is vast when there is a whole book written. I am trying to mention 3 easy steps we took in our recent project to get started:
- Renaming variables and method names. In all the modern IDE there is a feature of renaming the variables and method names. It’s safe because it will not break your compilation and still guarantee your code will be read better. The code is better from the time you do your first rename.
- Delete all commented code. It is self-explanatory. An excuse given is I may need the code in future. You can get your code back by using source control system, So use source control system to archive your code. Thus reducing the lines of code you don’t have to browse through your code at all.
- Extract method is one of the handy ways when your method starts growing huge. If we us the help of modern IDE it has the feature to do it safely. We have to be careful but IDE will help us in a great extent. This technique will also help in reading your code better.