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
Rechartsで楽にゴリゴリにカスタマイズする!
10tera
1
170
Jakarta EE meets AI
ivargrimstad
0
380
What you can do with Ruby on WebAssembly
kateinoigakukun
0
170
全部見せます! クラシルリワードのSwiftTesting移行プロジェクト
uetyo
0
210
The Sequel to a Dream of Ruby Parser's Grammar
ydah
1
220
From Idea to IDE: Developing Plugins for Android Studio
thisaay
1
220
マイグレーションコード自作して File-Based Routing に自動移行!! ~250 ページの歴史的経緯を添えて~
cut0
1
260
Modern Angular with the NGRX Signal Store New Rules for Your Architecture @BASTA! 2024 in Mainz
manfredsteyer
PRO
0
110
Regular Expressions, REXML, Automata Learning
makenowjust
0
220
React + TextAliveでカッコいいLyric Applicatioinを作ろう!!
tosuri13
0
400
Scala におけるコンパイラエラーとの付き合い方
chencmd
2
430
2024 컴포즈 정원사
jisungbin
0
150
Featured
See All Featured
Optimizing for Happiness
mojombo
375
69k
How STYLIGHT went responsive
nonsquared
93
5.1k
Learning to Love Humans: Emotional Interface Design
aarron
270
40k
Mobile First: as difficult as doing things right
swwweet
221
8.8k
The Art of Programming - Codeland 2020
erikaheidi
48
13k
4 Signs Your Business is Dying
shpigford
179
21k
The Invisible Side of Design
smashingmag
295
50k
Being A Developer After 40
akosma
84
590k
How To Stay Up To Date on Web Technology
chriscoyier
786
250k
Building Applications with DynamoDB
mza
90
6k
Adopting Sorbet at Scale
ufuk
73
8.9k
Optimising Largest Contentful Paint
csswizardry
30
2.8k
Transcript
リファクタリング 既存のコードを安全に改善する 意図が伝わるコードの書き方
リファクタリングとは? • プログラムの振る舞い(仕様)を変えずに内部品質を向上させる作業 • 内部品質: 保守性、可読性等 • バグ修正ではない(リファクタリングとバグ修正は別で行う) • 実現方法:
カプセル化、関数化、名前の変更等
ロジックを関数化する目的とは? 1. 再利用性を高める(同じ処理を繰り返し書かない) 2. 可読性を上げる(行数を減らす) 3. 意図を明確にする(何をやっているかを読み手に伝える)
サンプルコード(リファクタリング前) ※ if文の条件が長くなると単純に読み辛く、理解しづらいという問題も つまりどういうことだってばよ?
サンプルコード(リファクタリング後) 曜日判定ロジックを 別関数に抽出 週末は割増料金になることをより明確に表現 ※ ユニットテストのしやすさも向上
関数命名のセオリー 「実装」と「意図」を分離する つまり「どうやって処理を行っているか」ではなく 「何をしているか」に着目して命名する × isDayOfWeekZeroOne() ◦ isWeekend()