Skip to content

Commit

Permalink
Update task.md
Browse files Browse the repository at this point in the history
language checked
  • Loading branch information
stephen-hero authored and onewhl committed Jan 24, 2024
1 parent 9d087e5 commit 74232ae
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions RefactoringAndItsPurpose/WhatIsCodeRefactoring/Theory/task.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Task 1/2: What is code refactoring?

**_Refactoring_** is a process of modifying source code without changing its behavior. For example, renaming a method or
extracting a _magic constant_ into a separate variable. It improves code readability but doesn’t change what code does.
**_Refactoring_** is a process of modifying source code without changing its behavior. For example, this could involve renaming a method or
extracting a _magic constant_ into a separate variable. It improves code readability but doesn’t change what the code does.

The purpose of refactoring is to **improve code readability and simplify its maintenance**. Usually, software developers
work in teams on code bases and spend considerable time reading each other’s code, so it is important to make your code
The purpose of refactoring is to **improve code readability and simplify its maintenance**. Since software developers often
work in teams on codebases and spend considerable time reading each other’s code, it is important to make your code
clear and clean.

Let's take a look at two code snippets below.
Expand All @@ -26,8 +26,8 @@ public class Main {
}
```

In this snippet of code, method name `calculate` isn't descriptive, making it unclear what it calculates.
Variable `n` and method parameter `r` don't provide any information about their purpose.
In this snippet of code, the method name `calculate` isn't descriptive, making it unclear what it calculates.
The variable `n` and the method parameter `r` don't provide any information about their purpose.
The constant `3.14159` is hard-coded within the method, leading to lack of clarity.

**After refactoring:**
Expand All @@ -49,11 +49,11 @@ public class Main {
}
```

To improve readability of the original snippet of code, the following refactorings were applied:
To improve the readability of the original snippet of code, the following refactorings were applied:

- Method `calculate` was **renamed** to `calculateCircleArea` to better express its purpose: calculating the area of a
- The method `calculate` was **renamed** to `calculateCircleArea` to better express its purpose: calculating the area of a
circle.
- Variable `n` was **renamed** to `circleRadius` for better code clarity.
- Parameter `r` was **renamed** to `radius` for better code clarity.
- `PI_VALUE` constant was **extracted** to hold the value of `Pi` value, making the calculation formula more
- The variable `n` was **renamed** to `circleRadius` for better code clarity.
- The parameter `r` was **renamed** to `radius` to improve code clarity.
- A `PI_VALUE` constant was **extracted** to hold the value of `Pi`, making the calculation formula more
understandable and reusable.

0 comments on commit 74232ae

Please sign in to comment.