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.8k
It’s All About DevTools
studiomohawk
0
100
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
370
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
DevFest - Serverless 101 with Google Cloud Functions
tunmise
0
130
非ブラウザランタイムとWeb標準 / Non-Browser Runtimes and Web Standards
petamoriken
0
340
React 19でお手軽にCSS-in-JSを自作する
yukukotani
2
140
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
270
20年もののレガシープロダクトに 0からPHPStanを入れるまで / phpcon2024
hirobe1999
0
870
為你自己學 Python
eddie
0
200
Findy Team+ Awardを受賞したかった!ベストプラクティス応募内容をふりかえり、開発生産性向上もふりかえる / Findy Team Plus Award BestPractice and DPE Retrospective 2024
honyanya
0
110
歴史と現在から考えるスケーラブルなソフトウェア開発のプラクティス
i10416
0
150
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
820
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
160
生成AIでGitHubソースコード取得して仕様書を作成
shukob
0
550
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
660
Featured
See All Featured
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
920
Optimizing for Happiness
mojombo
376
70k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.9k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Done Done
chrislema
182
16k
Art, The Web, and Tiny UX
lynnandtonic
298
20k
GitHub's CSS Performance
jonrohan
1031
460k
It's Worth the Effort
3n
183
28k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
Git: the NoSQL Database
bkeepers
PRO
427
64k
Optimising Largest Contentful Paint
csswizardry
33
3k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
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