1
1
# Task 1/2: What is code refactoring?
2
2
3
- ** _ Refactoring_ ** is a process of modifying source code without changing its behavior. For example, renaming a method or
4
- extracting a _ magic constant_ into a separate variable. It improves code readability but doesn’t change what code does.
3
+ ** _ Refactoring_ ** is a process of modifying source code without changing its behavior. For example, this could involve renaming a method or
4
+ extracting a _ magic constant_ into a separate variable. It improves code readability but doesn’t change what the code does.
5
5
6
- The purpose of refactoring is to ** improve code readability and simplify its maintenance** . Usually, software developers
7
- work in teams on code bases and spend considerable time reading each other’s code, so it is important to make your code
6
+ The purpose of refactoring is to ** improve code readability and simplify its maintenance** . Since software developers often
7
+ work in teams on codebases and spend considerable time reading each other’s code, it is important to make your code
8
8
clear and clean.
9
9
10
10
Let's take a look at two code snippets below.
@@ -26,8 +26,8 @@ public class Main {
26
26
}
27
27
```
28
28
29
- In this snippet of code, method name ` calculate ` isn't descriptive, making it unclear what it calculates.
30
- Variable ` n ` and method parameter ` r ` don't provide any information about their purpose.
29
+ In this snippet of code, the method name ` calculate ` isn't descriptive, making it unclear what it calculates.
30
+ The variable ` n ` and the method parameter ` r ` don't provide any information about their purpose.
31
31
The constant ` 3.14159 ` is hard-coded within the method, leading to lack of clarity.
32
32
33
33
** After refactoring:**
@@ -49,11 +49,11 @@ public class Main {
49
49
}
50
50
```
51
51
52
- To improve readability of the original snippet of code, the following refactorings were applied:
52
+ To improve the readability of the original snippet of code, the following refactorings were applied:
53
53
54
- - Method ` calculate ` was ** renamed** to ` calculateCircleArea ` to better express its purpose: calculating the area of a
54
+ - The method ` calculate ` was ** renamed** to ` calculateCircleArea ` to better express its purpose: calculating the area of a
55
55
circle.
56
- - Variable ` n ` was ** renamed** to ` circleRadius ` for better code clarity.
57
- - Parameter ` r ` was ** renamed** to ` radius ` for better code clarity.
58
- - ` PI_VALUE ` constant was ** extracted** to hold the value of ` Pi ` value , making the calculation formula more
56
+ - The variable ` n ` was ** renamed** to ` circleRadius ` for better code clarity.
57
+ - The parameter ` r ` was ** renamed** to ` radius ` to improve code clarity.
58
+ - A ` PI_VALUE ` constant was ** extracted** to hold the value of ` Pi ` , making the calculation formula more
59
59
understandable and reusable.
0 commit comments