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: What, Why and When
Search
Yuya Saito
June 21, 2014
Programming
5
290
Refactoring: What, Why and When
リファクタリングとはなんなのか、どうして必要なのか、そしていつ実行するべきなのか。
本セッションではそんなリファクタリングの基礎について紹介していきます。
Yuya Saito
June 21, 2014
Tweet
Share
More Decks by Yuya Saito
See All by Yuya Saito
Design System as a Product @ Frontrend Vol.8
studiomohawk
2
4.7k
It’s All About DevTools
studiomohawk
0
99
Pragmatic Front-end Developer: From Artisan to Expert
studiomohawk
10
2k
Guiding Through The JavaScript Frameworks
studiomohawk
8
1.1k
CSSI: CSS Investigation
studiomohawk
21
9.5k
Performance in CSS
studiomohawk
5
360
Refactoring CSS
studiomohawk
9
530
Leveling Up Your Front-end skills
studiomohawk
6
1.4k
A Recipe for Modern Mobile Front-end Development
studiomohawk
16
5.5k
Other Decks in Programming
See All in Programming
2024/11/8 関西Kaggler会 2024 #3 / Kaggle Kernel で Gemma 2 × vLLM を動かす。
kohecchi
5
930
イベント駆動で成長して委員会
happymana
1
330
Contemporary Test Cases
maaretp
0
140
Outline View in SwiftUI
1024jp
1
330
Jakarta EE meets AI
ivargrimstad
0
220
Amazon Qを使ってIaCを触ろう!
maruto
0
410
Realtime API 入門
riofujimon
0
150
Laravel や Symfony で手っ取り早く OpenAPI のドキュメントを作成する
azuki
2
120
CSC509 Lecture 09
javiergs
PRO
0
140
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
10
1.3k
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
170
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
31
6.3k
The Cost Of JavaScript in 2023
addyosmani
45
6.8k
Code Reviewing Like a Champion
maltzj
520
39k
Faster Mobile Websites
deanohume
305
30k
Practical Orchestrator
shlominoach
186
10k
Music & Morning Musume
bryan
46
6.2k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
93
16k
Imperfection Machines: The Place of Print at Facebook
scottboms
265
13k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.7k
Keith and Marios Guide to Fast Websites
keithpitt
409
22k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Transcript
What, Why and When Refactoring Refactoring Yuya Saito @ Remixing
Remixing Welcome to
Yuya Saito @ Rich Media
Refactoring Refactoring ? ? ?
Agenda Agenda ϦϑΝΫλϦϯάͱͲΜͳͷͳͷ͔ ͳͥϦϑΝΫλϦϯάΛ͢Δඞཁ͕͋Δͷ͔ ͍ͭΔͷͳͷ͔ What Why When
Refactoring: Improving the Design of Existing Code by Martin Fowler
What What ϦϑΝΫλϦϯάͱ
“The first draft of anything is shit.” — Ernest Hemingway
Refactoring (noun): a change made to the internal structure of
software to make it easier to understand and cheaper to modify without changing its observable behaviour.
ϦϑΝΫλϦϯά ໊ࢺ ؍ଌͰ͖ΔৼΔ͍Λมߋ͢Δ͜ͱͳ͘ɺ ΑΓཧղ͘͢͠ɺมߋ͘͢͠ͳΔΑ͏ɺ ιϑτΣΞͷ෦తͳߏΛมߋ͢Δ͜ͱɻ
ιʔείʔυΛΩϨΠʹ͢Δ͜ͱ tl;dr
ཧղ͘͢͠ɺ Point 1/2 มߋ͘͢͢͠Δɻ ιϑτΣΞΛ
؍ଌՄೳͳৼΔ͍Λมߋ͠ͳ͍ Point 2/2
Why Why ͳͥඞཁͳͷ͔
100% 100%
42 42
Improves the Design of Software Refactoring Refactoring ιϑτΣΞͷσβΠϯΛ্ͤ͞Δ
None
σβΠϯ࣌ؒͷܦաʹΑͬͯ ࣭͕Լ͕͍ͬͯ͘ͷ
ϓϩάϥϛϯάͷੈքͰ ·ͬͨ͘ಉ͜͡ͱ͕ݴ͑Δ
มԽͷڱؒʹஔ͖Εͯ͠·ͬͨɺ ົͳʹ͓͍͕͢ΔίʔυΛݩʑͷσβΠϯʹ ߹Θͤͯॻ͖͑ΔͨΊʹଘࡏ͢Δɻ Refactoring Refactoring
Makes Software Easier to Understand Refactoring Refactoring ιϑτΣΞΛཧղ͢Δ͜ͱΛखॿ͚ͯ͘͠ΕΔ
Lazy Lazy
ॻ͍ͨίʔυʹ͓͖֮͑ͯ͘͜ͱ ͯ͢Λୗ͢ɻ ͨͣ͠ͷʮ͓͖֮͑ͯ͘ʯ͜ͱΛ ಡΈऔΕͳ͍ɻ u
ଞਓ͕ॻ͍ͨίʔυɺ ͕ࣗॻ͍ͨίʔυཧղͰ͖ΔΑ͏ ॻ͖͑Δɻ Refactoring Refactoring
When When ͍ͭϦϑΝΫλϦϯάΛ͢Δ͖͔
ࣗͷ͍ͨॴɺͦ͜Λग़ͯߦ͘ͱ͖ɺ དྷͨ࣌ΑΓ͖Ε͍ʹ͠ͳ͚ΕͳΒͳ͍ɻ — The Boy Scout Rule
ͲͷϓϩδΣΫτͰϦϑΝΫλϦϯά͕ ඞཁͰ͋Δͱ͍͏ೝ͕ࣝ͋Δɻ
Ͳ͏ͬͯϦϑΝΫλϦϯάͷ ࣌ؒΛ֬อ͢Δ͔ Problem is: Problem is:
Answer is Simple Answer is Simple ͦΜͳ͍࣌ؒͭ·Ͱͨͬͯ ֬อͰ͖ͳ͍ɻ
نͷେখ͋ΕͲιʔείʔυʹ ඞͣඒ͍͠ͱݴ͑ͳ͍෦͕͋Δͷɻ
ࣗͷ͍ͨॴɺͦ͜Λग़ͯߦ͘ͱ͖ɺ དྷͨ࣌ΑΓ͖Ε͍ʹ͠ͳ͚ΕͳΒͳ͍ɻ — The Boy Scout Rule
ϦϑΝΫλϦϯάظؒΛ ܾΊͯߦ͏ͷͰͳ͍ɻ
Rule of Three Rule of Three
1,2,_,_,_,_
1,2,3,_,_,_
None
“The first time you do something, you just do it.
The second time you do something similar, you wince at the duplication, but you do the duplicate thing anyway. The third time you do something similar, you refactor.” — Don Roberts
·ͣ࢝ΊͷճʹԿ͔Λ͢Δ߹ɺ ͨͩͦΕΛ͢Δ͚ͩɻ ճʹԿ͔ࣅͨ͜ͱΛ͢Δ߹ɺ ॏෳʹදΛಶΒͤͳ͕Βɺ ͦͷॏෳ͍ͯ͠Δ͜ͱΛ͢Δɻ ճʹͦͷࣅͨԿ͔Λ͢Δࡍɺ ϦϑΝΫλΛߦ͏ɻ — Don Roberts
Outro Outro ·ͱΊ
ͬͨΒɺม͑Δɻ — The Rule of Baby Rearing
Code smells Code smells
͍Λ͔͚͗Δೳྗ͕ܦݧͱΑΕΔͷ
Take away Take away
1/2
2/2 ϦϑΝΫλϦϯά ظؒΛܾΊͯߦ͏ͷͰͳ͘ɺ ௨ৗۀͷϫʔΫϑϩʔͰߦ͏ͷͰ͢ɻ
The Long Goodbye by Raymond Chandler
“There is no trap so deadly as the trap you
set for yourself.” — Philip Marlowe
“ࣗͰࣗʹֻ͚Δ᠘΄Ͳ ͨͪͷѱ͍᠘ͳ͍ɻ” — Philip Marlowe
Thank You! Thank You! @cssradar @cssradar