Major overhauling or redevelopment is something everybody faces at least once in their lives. Pipes and wiring wear out, finishing materials and interior items become outdated, the location of rooms ceases to be convenient. Refactoring is comparable to a major overhaul and involves redesigning and correcting the code. The internal structure of the program changes, while the behaviour remains the same.
Code refactoring is often required because:
- The architecture is subject to change;
- It is necessary to scale the solution;
- Productivity ought to be increased;
- The first version was made in a hurry or for ‘as cheap as possible’;
- There is a new version of the compiler or library;
- Past programmers may have made architectural mistakes;
- As the operation progresses, it becomes clear that new functions are needed.
Low-quality code is cumbersome and unreadable. It can easily be detected by common signs such as storing passwords in cookies, complex URLs, naming variables in different languages etc.
Refactoring fixes the following issues:
01 | Heterogeneous style of naming variables, methods, classes | |||
02 | Code duplication | |||
03 | Cluttered methods and classes | |||
04 | An overloaded list of parameters of functions and methods | |||
05 | Long branching blocks | |||
06 | Magic values | |||
07 | The use of incomprehensible abbreviations | |||
08 | Hard coding of assumptions | |||
09 | Excessive configuration | |||
10 | Confusing code | |||
11 | An excessive number of abstraction levels | |||
12 | Excessive interdependence of classes from one other | |||
13 | No input data validation | |||
14 | Overloading of classes and components with heterogeneous functionalities | |||
15 | Excessive generalization of the code | |||
16 | Storing temporary values in fields | |||
17 | Intermediary classes | |||
18 | Lack of class isolation | |||
19 | Inappropriate class inheritance | |||
20 | Inheritance instead of delegation | |||
21 | Logic outside of the domain classes | |||
22 | Direct calls between distant parts of the system | |||
23 | Unused code | |||
24 | CPU consumption in standby | |||
25 | Incorrect parallelization of tasks or lack of multi-threading implementation | |||
26 | A separate branch of the code for special cases | |||
27 | Self-written code in place of library-use | |||
28 | Insufficient commenting on the code or excessive commenting on obvious sections |

Refusal to refactor leads to the fact that any minor interference in the code will entail a series of errors and corrections. The second unpleasant consequence may be occasionally recurring critical errors that will be extremely difficult to reproduce, diagnose and debug. Finally, the gradual addition of new functions will lead to a layering of functionalities, which, in turn, will negatively affect the operation of the program and will damage the user experience.