You are viewing our old blog site. For latest posts, please visit us at the new space. Follow our publication there to stay updated with tech articles, tutorials, events & more.

Basics of Restructuring and Refactoring

0.00 avg. rating (0% score) - 0 votes

The code that seems clean and fresh today, will someday begin to smell… Thats when you rewrite it!!!

WHAT IS IT?

A passionate developer always tries to write clean and quality code. Contrary to that, we often find messy and unstructured code.

The transformation from a clean code to a messy code is a natural process where the code ‘ages’ with time.

With time the code gets modified by the same or a different programmer. These later additions to the code are primarily tweaks and fixes. These additions often do not fit with the existing code design and thus are placed with less emphasis than necessary. Therefore with time, the code becomes bulky and seems ‘out of place’.

Refactoring is a technique which results in small changes in our code thereby increasing the quality, maintainability while preserving the functional behavior.

When changes are made in the existing code by the developers to improve the overall structure of the code, that’s restructuring.

At a stage when the code has become old, restructuring is of primary importance. Restructuring is done by giving continuous attention to technical excellence and good design.

Naukrigulf Got Revamped

Naukrigulf’s Jobsearch was one such app that needed attention at high priority. All the developers saw the golden chance when the product manager asked for a revamped website. The requirements were put forward and the best and the most talented minds were brought together into a meeting room. Hours of discussions and weeks of coding resulted in a very modular and clean code that went live on 24th December, 2015.

THE RESULTS

* Cyclomatic Complexity was reduced by breaking long and complex code into much more modular and simpler classes.

* Refactoring a section of code requires a solid set of automatic unit tests. Good unit tests can catch enough errors to make them worthwhile and to make refactoring safe enough. More than 70% of the code written was covered by the unit tests, thus making the code impregnable.

* Vulnerability Assessment tests were carried out throughout the code, to prevent Cross Site Scripting attacks and SQL injections.

* The process of Continuous Integration and Continuous Deployment started with this revamp. Thus reducing the efforts of manually running the test cases and manually deploying the code on test servers.

* Readability and maintainability was greatly increased because the new code was much more modular and linear.

These finer points were achieved mainly because a firm MVC architecture was laid down. New and logical classes were created. All the coding guidelines were followed. “One class, One logic” rule was of prime importance. Design principles were thoroughly followed so as to maintain high coding standards and code quality.

Conclusion

Restructuring and refactoring do not always result in the progress of a product. It is merely the same code with a new design. This is one of the prominent reasons for a firm not to invest time and resources in restructuring and refactoring.

It is very important to realize that the restructuring can be more costly than the restructured code is worth. In this case it is best to postpone the activity for a later time.

Utilizing the resources for a new feature and new code or restructuring the old code is a tradeoff that every firm has to take at the right time, so that its progress is never hindered.