11.1 Refactoring Function Program
Refactoring is a major part of many modern development methods. In some languages, this technology also supports the integrated development environment (IDE), such as the C # Editor in Visual Studio. Most refactoring techniques are developed for object-oriented paradigms, but we will discuss them from a functional perspective.
Refactoring
Refactoring is the process of modifying the source code, improving the design, but not changing its meaning. The goal of refactoring is to make the code more readable, easier to modify or extend in the future, or to improve its structure. A simple refactoring example is renaming a method that makes the name more descriptive, and another example of converting a piece of code into a method for reuse to avoid code duplication.
With refactoring, we first write the code that works, and then make the code more "clean." The two tasks are performed separately, simplifying the test because refactoring does not affect the behavior of the application. Some of the changes are fairly simple, such as renaming (especially with tools), while others may require more thoughtful consideration.
If you change the order of two statements, will the code behave the same way? Using imperative code with side-effects, these two statements must be carefully examined, and functional programming makes the code easier to infer, so refactoring becomes easier. In this section, we'll have a few examples, but start with a functional refactoring that eliminates repetitive code.
11.1 Refactoring Function Program