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
Better Code Design in PHP
afilina
PRO
0
120
受け取る人から提供する人になるということ
little_rubyist
0
230
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
600
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
1.9k
エンジニアとして関わる要件と仕様(公開用)
murabayashi
0
280
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
as(型アサーション)を書く前にできること
marokanatani
9
2.6k
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
弊社の「意識チョット低いアーキテクチャ」10選
texmeijin
5
24k
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.4k
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
250
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
8
860
How to train your dragon (web standard)
notwaldorf
88
5.7k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
Ruby is Unlike a Banana
tanoku
97
11k
YesSQL, Process and Tooling at Scale
rocio
169
14k
Automating Front-end Workflow
addyosmani
1366
200k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.3k
GraphQLの誤解/rethinking-graphql
sonatard
67
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