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 44f28c5 commit d50dbbc
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions ExtractingCode/WhatIsExtractMethodRefactoring/Theory/task.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Task 1/2: What is Extract Method refactoring?

As we mentioned before, **duplicated code can lead to undesirable effects**, such as when you fix a bug in one place
but forget to fix it consistently in duplicates.
The bug will still remain, and now it is even harder to find.
As we mentioned before, **duplicated code can lead to undesirable effects**. For example, if you fix a bug in one place
but forget to fix it consistently in duplicates,
the bug will still remain, and now it is even harder to find.

We recommend avoiding duplicated code, but what can you do if it already exists?
The solution is to **extract the duplicated code into a new separate function** and replace all the duplicated code fragments
with calls to the newly introduced function.
It is called an **Extract Method**.
It is called the **Extract Method**.

Also, we apply Extract Method refactoring when we encounter **long methods**.
While there's no fixed limit on the number of lines a method should have, **consider extracting
Also, we apply the Extract Method refactoring when we encounter **long methods**.
While there's no fixed limit on a method's line count should have, **consider extracting
a block of code statements into a separate method** if those statements are cohesive
and expose a piece of functionality that can be reused in other places.
and represent a piece of functionality that could be reused elsewhere.
This also improves code readability and organization.

Smaller functions make the code easier to read and understand, as each method has one single responsibility,
Expand Down

0 comments on commit d50dbbc

Please sign in to comment.