Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
refactoring
Search
mazua
August 20, 2021
Programming
22k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
refactoring
mazua
August 20, 2021
Transcript
6 slides
リファクタリング 既存のコードを安全に改善する 意図が伝わるコードの書き方
リファクタリングとは? • プログラムの振る舞い(仕様)を変えずに内部品質を向上させる作業 • 内部品質: 保守性、可読性等 • バグ修正ではない(リファクタリングとバグ修正は別で行う) • 実現方法:
カプセル化、関数化、名前の変更等
ロジックを関数化する目的とは? 1. 再利用性を高める(同じ処理を繰り返し書かない) 2. 可読性を上げる(行数を減らす) 3. 意図を明確にする(何をやっているかを読み手に伝える)
サンプルコード(リファクタリング前) ※ if文の条件が長くなると単純に読み辛く、理解しづらいという問題も つまりどういうことだってばよ?
サンプルコード(リファクタリング後) 曜日判定ロジックを 別関数に抽出 週末は割増料金になることをより明確に表現 ※ ユニットテストのしやすさも向上
関数命名のセオリー 「実装」と「意図」を分離する つまり「どうやって処理を行っているか」ではなく 「何をしているか」に着目して命名する × isDayOfWeekZeroOne() ◦ isWeekend()
More Decks by mazua
See All by mazua
初めてのPHP.pdf
azuma
0
22k
Other Decks in Programming
See All in Programming
自宅サーバはどこまで再現できるのか - Proxmox VE上のVM環境をIaCとバックアップで戻してみた
youto
0
440
祈るテストから、探索するテストへ 〜Lincheckではじめる並行処理テスト〜
yyh_gl
0
350
例外からRich Errorsまで Kotlinエラーハンドリングの進化を読み解く
shiita0903
0
230
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
1k
将来の標準フォーマッター?ktfmtを深堀る
t45k
0
220
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
290
Crash Auto Pipelines
veronikapj
1
440
우리의 Nitro Modules는 당신의 Turbo Modules보다 아름답다
l2hyunwoo
0
270
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
600
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
780
Spec-driven Development with AI
simas
PRO
0
2.3k
Kawaiicon: Kubernetes, it's no longer cool, but let's secure it anyway!
barnbarn
0
140
Featured
See All Featured
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
70
69k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
It's Worth the Effort
3n
188
29k
Paper Plane
katiecoart
PRO
6
55k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
23k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Code Reviewing Like a Champion
maltzj
529
40k
SERP Conf. Vienna - Web Accessibility: Optimizing for Inclusivity and SEO
sarafernandez
2
1.7k
svc-hook: hooking system calls on ARM64 by binary rewriting
retrage
2
680
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Design in an AI World
tapps
1
390