リファクタリング
10416 ワード
グループ化し、原子的に呼び出すことができるコードスニペットを見つけます.
問題点読みやすさ 複雑さ コード再利用
関連する匂い
ステップは、別の新しい方法 にコード断片を動かします古いコードを最近作成されたメソッドの呼び出しに置き換えます.
サンプルコード
以前
アフター
種類
自動化
多くのIDEがこの安全なリファクタリングをサポートします
制限
使用する場合はうまくいきません.
タグ複雑さ 読みやすさ
関連リファクタリング新しいクラス へのメソッドの移動
クレジット
HreishoからのPixabayによるイメージ
この記事はリファクタリングシリーズの一部です.
TL;DR: Group your cohesive sentences together
問題点
関連する匂い
Code Smell 03 - Functions Are Too Long
Maxi Contieri ・ Oct 22 '20 ・ 1 min read
#codenewbie
#beginners
#programming
#100daysofcode
Code Smell 05 - Comment Abusers
Maxi Contieri ・ Oct 24 '20 ・ 2 min read
#codenewbie
#tutorial
#beginners
Code Smell 18 — Static Functions
Maxi Contieri ・ Nov 6 '20 ・ 2 min read
#codenewbie
#tutorial
#development
#coding
Code Smell 22 - Helpers
Maxi Contieri ・ Nov 12 '20 ・ 2 min read
#oop
#helpers
#codenewbie
#beginners
Code Smell 74 - Empty Lines
Maxi Contieri ・ Jun 4 '21 ・ 1 min read
#codenewbie
#tutorial
#oop
#programming
Code Smell 78 - Callback Hell
Maxi Contieri ・ Jun 11 '21 ・ 2 min read
#javascript
#node
#oop
#tutorial
Code Smell 102 - Arrow Code
Maxi Contieri ・ Nov 15 '21 ・ 2 min read
#oop
#javascript
#cleancode
#refactoring
ステップ
サンプルコード
以前
object Ingenuity {
fun moveFollowingPerseverance() {
//take Off
raiseTo(10 feet)
//move forward to perseverance
while (distanceToPerseverance() < 5 feet){
moveForward()
}
//land
raiseTo(0 feet)
}
アフター
object Ingenuity {
//1. Move the code fragment to a separate new method
private fun takeOff() {
raiseTo(10 feet)
}
//1. Move the code fragment to a separate new method
private fun moveForwardToPerseverance() {
while (distanceToPerseverance() < 5 feet){
moveForward()
}
}
//1. Move the code fragment to a separate new method
private fun land() {
raiseTo(0 feet)
}
fun moveFollowingPerseverance() {
takeOff()
//2. Replace the old code with a call to the recently created method.
moveForwardToPerseverance()
//2. Replace the old code with a call to the recently created method.
land()
//2. Replace the old code with a call to the recently created method.
}
}
種類
自動化
多くのIDEがこの安全なリファクタリングをサポートします
制限
使用する場合はうまくいきません.
タグ
関連リファクタリング
クレジット
HreishoからのPixabayによるイメージ
この記事はリファクタリングシリーズの一部です.
Reference
この問題について(リファクタリング), 我々は、より多くの情報をここで見つけました https://dev.to/mcsee/refactoring-002-extract-method-1eeeテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol