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
とにかくAWS GameDay!AWSは世界の共通言語! / Anyway, AWS GameDay! AWS is the world's lingua franca!
seike460
PRO
1
510
生成 AI を活用した toitta 切片分類機能の裏側 / Inside toitta's AI-Based Factoid Clustering
pokutuna
0
560
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
190
Sidekiqで実現する 長時間非同期処理の中断と再開 / Pausing and Resuming Long-Running Asynchronous Jobs with Sidekiq
hypermkt
6
2.6k
Pinia Colada が実現するスマートな非同期処理
naokihaba
2
150
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
1.3k
WEBエンジニア向けAI活用入門
sutetotanuki
0
300
詳細解説! ArrayListの仕組みと実装
yujisoftware
0
470
VR HMDとしてのVision Pro+ゲーム開発について
yasei_no_otoko
0
100
破壊せよ!データ破壊駆動で考えるドメインモデリング / data-destroy-driven
minodriven
16
4k
PHP でアセンブリ言語のように書く技術
memory1994
PRO
1
150
Identifying User Idenity
moro
6
7.6k
Featured
See All Featured
RailsConf 2023
tenderlove
29
880
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
7
150
Into the Great Unknown - MozCon
thekraken
31
1.5k
The Invisible Side of Design
smashingmag
297
50k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
26
2k
Building Adaptive Systems
keathley
38
2.2k
It's Worth the Effort
3n
183
27k
Statistics for Hackers
jakevdp
796
220k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
Fireside Chat
paigeccino
32
3k
How to Think Like a Performance Engineer
csswizardry
19
1.1k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
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