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
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
[KR] Server Driven Compose With Firebase
skydoves
2
160
App Router 悲喜交々
quramy
7
370
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
1.1k
GitHub Copilot Workspace で我々のアプリ開発がどう変わるのか?
shuyakinjo
0
860
Go製CLIツールGatling Commanderによる負荷試験実施の自動化
okmtz
3
670
色んなオートローダーを覗き見る #phpcon_okinawa
o0h
PRO
5
370
Cloud Adoption Frameworkにみる組織とクラウド導入戦略(縮小版)
tomokusaba
1
170
"noncopyable types" の使いどころについて考えてみた
andpad
0
130
Flutterアプリを生成AIで生成する勘所
rizumita
0
250
Vue :: Better Testing 2024
up1
1
380
perl for shell, awk and sed programmers
mackee
1
380
型付きで行うVSCode拡張機能開発 / VSCode Meetup #31
mazrean
0
230
Featured
See All Featured
Music & Morning Musume
bryan
46
6.1k
Bootstrapping a Software Product
garrettdimon
PRO
304
110k
Docker and Python
trallard
40
3k
Build your cross-platform service in a week with App Engine
jlugia
229
18k
How GitHub (no longer) Works
holman
311
140k
Into the Great Unknown - MozCon
thekraken
30
1.4k
What's in a price? How to price your products and services
michaelherold
243
11k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.3k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
4 Signs Your Business is Dying
shpigford
180
21k
Practical Orchestrator
shlominoach
185
10k
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