Code refactoring

Code refactoring

November 1, 2021

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:

  1. The first version was made in a hurry or for ‘as cheap as possible’;
  2. There is a new version of the compiler or library;
  3. Past programmers may have made architectural mistakes;
  4. As the operation progresses, it becomes clear that new functions are needed.
Info

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 naming variables Heterogeneous style of naming variables, methods, classes
02 Code duplication Code duplication
03 Cluttered classes Cluttered methods and classes
04 An overloaded list An overloaded list of parameters of functions and methods
05 Long branching blocks Long branching blocks
06 Magic values Magic values
07 Incomprehensible abbreviations The use of incomprehensible abbreviations
08 Hard coding Hard coding of assumptions
09 Excessive configuration Excessive configuration
10 Confusing code Confusing code
11 Abstraction levels An excessive number of abstraction levels
12 Interdependence of classes Excessive interdependence of classes from one other
13 No data validation No input data validation
14 Overloading of classes Overloading of classes and components with heterogeneous functionalities
15 Generalization code Excessive generalization of the code
16 Temporary values in fields Storing temporary values in fields
17 Intermediary classes Intermediary classes
18 Lack of class isolation Lack of class isolation
19 Inappropriate class inheritance Inappropriate class inheritance
20 Inheritance instead of delegation Inheritance instead of delegation
21 Logic outside of the domain classes Logic outside of the domain classes
22 Direct calls Direct calls between distant parts of the system
23 Unused code Unused code
24 CPU consumption CPU consumption in standby
25 Incorrect parallelization CPU Incorrect parallelization of tasks or lack of multi-threading implementation
26 Separate branch A separate branch of the code for special cases
27 Library Self-written code in place of library-use
28 Insufficient commenting 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.