Subscribe by Email


Sunday, April 15, 2012

What is meant by refactoring of code?

Re-factoring of code or code refactoring is the topic of discussion of this article.

We can define the code refactoring technique as one of the disciplined techniques which is used for the following purposes:

- Restructuring of an existing body of the source code,
- Alteration of the internal structure of the code such that its external behavior remains the unaltered.

About Code Re-factoring



- The above two purposes are achieved by the application of a series of refactorings. - Each of the refactorings of the series is usually a tiny change in the source code of the computer program.
- The code refactoring technique is deployed for making improvements in the non – functional attributes of the software system or applications.
- A refactoring is not intended towards the modification of the functional requirements of the software system or application.

Advantages of Code Re-factoring


There are many advantages of the code re-factoring technique, few of which have been mentioned below:

- Improves the readability of the source code of the software system or application.
- Reduces the complexity of the code so as to improve it maintainability.
- Provides a more expressive object model or we can say an internal architecture for improving the extensibility and so on.

How is Re-factoring of code done?


It is obvious that with the continuous improvement in the design of the source code, it becomes better in its working and performing tasks.

- The developers, programmers and testers usually keep on adding new features in to the software system or application without performing adequate code refactoring which is quite an unhygienic technique.

- Carrying out the code re-factoring process continuously makes it easier to maintain and extend the source code of the program.

- The motivation to the code re-factoring is often provided by the code smell.

- Up on the identification of the problem, they can be effectively fixed by a series of code re-factoring.

- The code re-factoring solves the problem by simply transforming it in to a new form that possesses the same behavior as was in its previous form but the code is no longer found to “smell”.

- For re-factoring the longer routine, it is often sub divided into smaller sub routines which are then individually re-factorized.

- And for the duplicate routines, the duplicate is discarded and one shared function in its place is used.

- Technical debt is a serious consequence that can be faced if the code refactoring is not done effectively.

Categories in which benefits of code re-factoring should fall


The benefits of the code re-factoring usually fall in to two basic categories:

1. Extensibility
- After re-factoring, it becomes extremely easy for extending the capabilities of the software system or application if it makes use of design patterns that are recognizable and also provides flexibility in those parts of the program where there was no flexibility previously.

2. Maintainability

- Up on the code refactoring it becomes a lot easier to fix the errors and bugs because the readability of the code increases and then it becomes easy to grasp what the author intends to achieve.

- The maintainability is increased by the division of a monolithic routine in to individual single purpose methods and by placing them in to a more appropriate class.

- A solid set of automated unit tests is required before you start the process of code re-factoring.

- These tests will demonstrate the correctness of the module and then the whole process enters in to an iterative cycle making small program transformations each time iteration takes place.

- Whenever a test fails, you can undo the last transformation and keep on trying until you get it right. Such small transformations make your program what you want it to be!


No comments:

Facebook activity