Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
refactoring
Search
mazua
August 20, 2021
Programming
1
21k
refactoring
mazua
August 20, 2021
Tweet
Share
More Decks by mazua
See All by mazua
初めてのPHP.pdf
azuma
0
21k
Other Decks in Programming
See All in Programming
git worktree × Claude Code × MCP ~生成AI時代の並列開発フロー~
hisuzuya
1
510
Select API from Kotlin Coroutine
jmatsu
1
190
PHPで始める振る舞い駆動開発(Behaviour-Driven Development)
ohmori_yusuke
2
230
関数型まつりレポート for JuliaTokai #22
antimon2
0
160
Team operations that are not burdened by SRE
kazatohiei
1
260
エンジニア向け採用ピッチ資料
inusan
0
170
ASP.NETアプリケーションのモダナイズ インフラ編
tomokusaba
1
420
GoのGenericsによるslice操作との付き合い方
syumai
3
690
Go1.25からのGOMAXPROCS
kuro_kurorrr
1
820
Beyond Portability: Live Migration for Evolving WebAssembly Workloads
chikuwait
0
400
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
660
Cline指示通りに動かない? AI小説エージェントで学ぶ指示書の書き方と自動アップデートの仕組み
kamomeashizawa
1
580
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
7
710
How STYLIGHT went responsive
nonsquared
100
5.6k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
53
2.8k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
Building Adaptive Systems
keathley
43
2.6k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
331
22k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
107
19k
It's Worth the Effort
3n
185
28k
What's in a price? How to price your products and services
michaelherold
246
12k
Docker and Python
trallard
44
3.4k
The Art of Programming - Codeland 2020
erikaheidi
54
13k
Transcript
リファクタリング 既存のコードを安全に改善する 意図が伝わるコードの書き方
リファクタリングとは? • プログラムの振る舞い(仕様)を変えずに内部品質を向上させる作業 • 内部品質: 保守性、可読性等 • バグ修正ではない(リファクタリングとバグ修正は別で行う) • 実現方法:
カプセル化、関数化、名前の変更等
ロジックを関数化する目的とは? 1. 再利用性を高める(同じ処理を繰り返し書かない) 2. 可読性を上げる(行数を減らす) 3. 意図を明確にする(何をやっているかを読み手に伝える)
サンプルコード(リファクタリング前) ※ if文の条件が長くなると単純に読み辛く、理解しづらいという問題も つまりどういうことだってばよ?
サンプルコード(リファクタリング後) 曜日判定ロジックを 別関数に抽出 週末は割増料金になることをより明確に表現 ※ ユニットテストのしやすさも向上
関数命名のセオリー 「実装」と「意図」を分離する つまり「どうやって処理を行っているか」ではなく 「何をしているか」に着目して命名する × isDayOfWeekZeroOne() ◦ isWeekend()