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
A Philosophy of Software Design 前半
Search
Yosuke Furukawa
PRO
February 28, 2022
Programming
26
11k
A Philosophy of Software Design 前半
2022/02/28 に MoneyForward で発表した A Philosophy of Software Design の話です。
Yosuke Furukawa
PRO
February 28, 2022
Tweet
Share
More Decks by Yosuke Furukawa
See All by Yosuke Furukawa
tc39 x jsconf.jp Panel Discussion 2024
yosuke_furukawa
PRO
0
150
Removing Corepack
yosuke_furukawa
PRO
9
1.3k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.5k
Strip Types と Storage
yosuke_furukawa
PRO
4
340
Module Harmony について
yosuke_furukawa
PRO
3
1.5k
LTのやり方
yosuke_furukawa
PRO
16
2.2k
AppRouter Panel Talk
yosuke_furukawa
PRO
3
700
Node.js v22 で変わること
yosuke_furukawa
PRO
13
5.3k
リアーキテクトと開発生産性について
yosuke_furukawa
PRO
25
9.6k
Other Decks in Programming
See All in Programming
Nurturing OpenJDK distribution: Eclipse Temurin Success History and plan
ivargrimstad
0
920
Flutterを言い訳にしない!アプリの使い心地改善テクニック5選🔥
kno3a87
1
180
Remix on Hono on Cloudflare Workers
yusukebe
1
290
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
最新TCAキャッチアップ
0si43
0
140
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
520
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
카카오페이는 어떻게 수천만 결제를 처리할까? 우아한 결제 분산락 노하우
kakao
PRO
0
110
cmp.Or に感動した
otakakot
3
180
ペアーズにおけるAmazon Bedrockを⽤いた障害対応⽀援 ⽣成AIツールの導⼊事例 @ 20241115配信AWSウェビナー登壇
fukubaka0825
6
1.9k
Less waste, more joy, and a lot more green: How Quarkus makes Java better
hollycummins
0
100
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
67
10k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
665
120k
Raft: Consensus for Rubyists
vanstee
136
6.6k
Fashionably flexible responsive web design (full day workshop)
malarkey
405
65k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
Code Review Best Practice
trishagee
64
17k
For a Future-Friendly Web
brad_frost
175
9.4k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
506
140k
It's Worth the Effort
3n
183
27k
The Art of Programming - Codeland 2020
erikaheidi
52
13k
Transcript
A philosophy of software design (લ) 2022/2/28 @ MoneyForward ษڧձ
Twitter: @yosuke_furukawa Github: yosuke-furukawa
A philosophy of software design • 2018ʹॳ൛͕ϦϦʔε͞Ε • 2020ʹୈೋ൛͕ϦϦʔε͞Εͨ •
Ͱ͍͏ͱʮιϑτΣΞઃܭͷֶʯ https://www.amazon.co.jp/dp/B07N1XLQ7D/
A philosophy of software design • ஶऀδϣϯɾΦʔελʔϋτ͞Μ • Stanford େֶͷίϯϐϡʔλαΠΤϯεڭत
• Sprite OS (OS), Tcl.Tk(ϓϩάϥϛϯάݴޠ), RAMCloud (ΫϥυγεςϜ) ͳͲͳͲɺ੍ ࡞ଟ https://web.stanford.edu/~ouster/cgi-bin/ home.php
A philosophy of software design ͷݴ͍͍ͨࠜຊʹ͋Δͱ͜Ζ • ιϑτΣΞͷઃܭָ͍͠ • ७ਮͳ࡞աఔͷதͰύζϧͷΑ͏ʹͲ͏ͬͯઃܭ͢Δ͔
Λߟ͑Δ͜ͱɺͦΕΛ࣮͢Δ͜ͱͷָ͍͘͢͜͝͠ͱ • ͜ͷ෦Λָ͠ΊΔΑ͏ʹͳͬͯ΄͍͠ • ٯʹݴ͏ͱΞυϗοΫʹϫʔʔ͍͖ͬͯͳΓॻ͍ͪΌ͔ͬͯ ΒςετΛॻ͍ͨΓ৭ʑޙ͔Βྑ͘͢ΔɺΈ͍ͨͳ͜ͱࠓ ͷτϨϯυͰ͋Δͷͷɺྑ͍࡞աఔʹͳ͍ͬͯͳ͍
ͦͦઃܭϓϩηεΛͪΌ Μͱఔͱ͍ͯͬͯ͠Δͱ ͜Ζগͳ͍
ྫ͑... • ΞδϟΠϧ։ൃ • εϓϦϯτͰ2िؒͷΰʔϧΛܾΊͯͦΕʹ͚ͯ ։ൃΛ͍ͯ͘͠ • ͢ΔͱͲ͏࣮ͯ͠ʹλεΫ͕ϑΥʔΧε͞ΕΔ • ݁Ռͱͯ͠࠷ॳ͔Βʮϫʔʔ࣮ͬͯͯ͠ɺޙ͔Β
ςετॻ͘ʯʹͳΓ͕ͪ
ྫ͑... • ҰਓͷϑϧελοΫϓϩάϥϚʔ͚͕ͩΞαΠ ϯ͞ΕͯϓϩδΣΫτΛճ͠ଓ͚ΔΑ͏ͳঢ়گ • ԿͰΒͳ͍ͱ͍͚ͳ͍ঢ়گʹ͍ࠐ·Εͯ Δ • ϫʔʔͬͱॻ͚ͩ͘ʹͳΓ͕ͪɺͱ͍͏͔ͦ ͏͡Όͳ͍ͱऴΘΒͳ͍ঢ়گʹͳͬͯΔ
ྫ͑... • ͳΜͱͳ͘ͷ֤ʹؕΓ͕ͪ • ϑϨʔϜϫʔΫԿΛ͏ʁ • πʔϧΛͲ͏͢Δʁ • ςετͲ͏ͬͯॻ͘ʁ •
Ͳ͏ͬͯ࡞Δ͔ͷٞΑΓલʹ͜ͷ͕དྷͯ͠·͏έʔε͕༗Δɻ • ͜ͷखͷϑϨʔϜϫʔΫπʔϧͷબఆ࣮ʹ͍ۙ • ܾΊͨΒʮϫʔʔͬͱॻ͘ʯࣄʹΓ͕ͪ
͜͏͍͏ʮϫʔʔͬͱॻͩ͘ ͚ॻ͘ʯͱ͍͏ϓϩάϥϛϯ άΛ൱ఆ͍ͯ͠Δ
tactical programming vs strategic programming • ʮϫʔʔͬͱॻ͚ͩ͘ॻ͘ʯͱ͍͏ͷ͜ͷຊͰ tactical programming ͱݺΕ͓ͯΓɺ൱ఆ͞Ε͍ͯΔɻ
• ·ͣͲ͏ͬͯෳࡶ͞ΛΓ͚Δ͔ͱݴͬͨͷղ ͱͦΕΛͲ͏ͬͯදݱ͢Δ͔ͱ͍͏நԽΛͪΌΜͱߦ ͏͖ͩͱ͍͏ओு • ͜ͷෳࡶ͞ͱ͖߹ͬͯίʔυΛॻ͘͜ͱΛʮstrategic programmingʯ ͱݺΜͰ͓Γɺͪ͜ΒΛਪ͍ͯ͠Δɻ
ෳࡶ͞ͱ͖߹͏
ιϑτΣΞ։ൃʹෳࡶ͕͞ ͖ͭͷ • ෳࡶ͞ͷΓཱͪΛΓ • ෳࡶ͞ΛͲ͏ͬͯॲཧ͢Δ͔Λߟ͑Δ • ͦΕ͕ͦ͜ "ઃܭ" Ͱ͋Δ
ͦͦෳࡶ͞ͱ
ෳࡶ͞ • "Complexity is anything related to the structure of
a software system that makes it hard to understand and modify the system." • ʮෳࡶ͞ͱιϑτΣΞγεςϜͷߏʹ ؔͯ͠ɺγεςϜͦͷͷΛཧղɾมߋ͠ʹ͘ ͍ͯ͘͠ΔԿ͔ʯͰ͋Δɻ
ෳࡶ͞ʹΑͬͯҾ͖ى͜͞ΕΔ ঢ়ଶ • มߋͷ֦େԽ (Change Amplification) • ೝෛՙͷ૿Ճ (Cognitive Load)
• Βͳ͍͜ͱͷ૿Ճ (Unknown Unknowns)
มߋͷ֦େԽ (Change Amplification) • มߋՕॴ͕ଟ͘ͳΔ͜ͱ • ҰՕॴม͑ΕࡁΈͦ͏ͳมߋ͚ͩͲɺ࣮ผͳՕॴ ม͑ͳ͖Ό͍͚ͳ͍έʔε • ྫ͑ɺഎܠ৭ͷมΛݸʑͷϖʔδ͕͍࣋ͬͯͯɺશ
ମΛม͑Δ࣌ʹҰݸҰݸͷϖʔδʹมߋ͕ٴΜͰ͠·͏ • ͜͏͍͏ͷมߋՕॴͷӨڹΛ࠷খݶʹ͠Α͏ͱͨͨ͠ Ίʹ tactic ͳίʔυ͕ੵΈॏͳͬͯى͖Δ
มߋͷ֦େԽ (Change Amplification) ҰՕॴͰม͑ΒΕΔΑ͏ʹͳ͍ͬͯͳ͍ྫ
ೝෛՙͷ૿Ճ (Cognitive Load) • ୯७ʹಡΈʹ͍͘ίʔυ • ίʔυ͕ϕλοͱॻ͔Ε͍ͯͯɺؔͱ͔Ϋϥε ͱ͔ͰͪΌΜͱׂ͞Εͯͳ͔ͬͨΓɺҰՕॴͰ ৭ʑΓ͗ͩͬͨ͢Γɺͦͦมɾ໊͕ؔ ײͱ߹Θͳ͔ͬͨΓ
• Α͘ݴΘΕͯΔΫιίʔυͬͯݺΕͨΓɺώϤ ίʔυͬͯݺΕͨΓ͢Δͭ
Βͳ͍͜ͱͷ૿Ճ (Unknown Unknowns) • ༁͢ΔͱʮΒͳ͍͜ͱʯΛΒͳ͍͜ͱ • ͦͷλεΫΛऴ͑ΔͷʹͲ͜·ͰνΣοΫ͢Ε͍ ͍͔͕ෆ໌ྎͳ͜ͱ • มߋͨ͠Βʮ࣮͜͜ʹӨڹ͋Γ·ͨ͠ʔʯͳࣄ
͕ӅΕͯΔ • ʮӅΕͨӨڹ㲈Α͘Βͳ͍͜ͱʯ͕Θ͔Βͳ͍͜ͱ
Βͳ͍͜ͱͷ૿Ճ (Unknown Unknowns) ҰՕॴͰม͑ΒΕΔΑ͏ʹͳͬͨͷͷɺ࣮ emphͱ͍͏ผͳछྨͷมͰݸʑʹϖʔδ৭੍͕ޚ͞Ε͍ͯΔྫ FNQI͕ VOLOPXO
ͳΜͰෳࡶʹͳΔͷ͔
ෳࡶʹͳΔཧ༝ • "Complexity comes from an accumulation of dependencies and
obscurities. (snip) As a result, it takes more code modifications to implement each new feature." • ʮෳࡶ͞ґଘͱᐆດ͞ͷੵ͔ΒͨΒ͞ ΕΔɻ݁Ռͱͯ͠কདྷͷػೳ࣮ͷͨΊʹΑ Γଟ͘ͷίʔυมߋ͕ඞཁʹͳΔʯ
ґଘ (dependencies) • ґଘࣗମආ͚ΒΕͳ͍ • ϥΠϒϥϦͷґଘ • ࣗͷ࡞ͬͨผͳΫϥεͷґଘ • ඞͣଘࡏ͢ΔɺΉ͠Ζແ͠Ͱ։ൃ͕Ͱ͖
ͳ͍
ґଘ (dependencies) • ॏཁͳͷґଘͦͷͷΛආ͚Δ͜ͱͰͳ ͘ɺԿͷͨΊʹґଘ͍ͯ͠Δͷ͔ɺͲ͏ͬͯ ґଘ͍ͯ͠Δͷ͔Λ໌֬ʹ͢Δ͜ͱ • background color ͷྫͰݴ͑ɺ͜ΕΛม͑
Εશͯͷഎܠ৭͕มΘΔ͜ͱΛ໌֬ʹ͢Δɻ • ٯʹݴ͑ෆ໌ྎͳґଘආ͚Δɻ
ᐆດ͞ (obscurity) • ᐆດͳίʔυͷྫ • Ұൠత͗͢Δม໊ (data, time, num) •
υΩϡϝϯτʹ୯Ґ͕໌ه͞Ε͍ͯͳ͍ (width, height => pixel? inch? cm?) • Ұ؏ੑ͕ͳ͍ίʔυ • ґଘʹΑͬͯᐆດ͕͞Ҿ͖ى͜͞ΕΔέʔε༗Δ • ґଘͨ͠ίʔυͷதͰ৽͍͠Τϥʔ͕Ճ͞ΕͨΓɺڍಈͷมߋ͕ ى͖ͯͦΕ͕໌ه͞Ε͍ͯͳ͔ͬͨΓ
ᐆດ͞ (obscurity) • Ұ൪ଟ͍ͷʮυΩϡϝϯτෆʯʹΑΔᐆ ດ͞ • ͳΜͰυΩϡϝϯτʹॻ͚Αͱ͍͏Ͱ ͳ͍ɻ • γϯϓϧͳઃܭʹΑͬͯυΩϡϝϯτ͕ͦ͜
·Ͱඞཁͳ͘ͳΔ͜ͱ͋Δ
Strategic Programming
Strategic Programming • ϫʔʔͬͱίʔυΛॻ͘ tactical programming Ͱͳ͘ɺ ෳࡶ͞ͱ͖߹͏ Strategic Programming
Λਪ͍ͯ͠Δ • Α͋͘Δٕज़తෛ࠴ tactical programming ʹΑͬͯى͜Δ • Strategic Programming ʹࢿϚΠϯυ͕ඞཁ • ࠷Λࢦͯ͠ίʔυΛॻ͍ͯऴΘΒͤΑ͏ͱ͢ΔͷͰͳ ͘ɺҰ୴ෳࡶ͞ͱ͖߹ͬͯઃܭͷྑ͠ѱ͠Λߟ͑ͳ͕Β ίʔυΛॻ͘͜ͱ͕ॏཁ
ࢿϚΠϯυ • ྑ͍ઃܭແྉͰ࡞Εͳ͍ • ແྉͰͳ͍ͷͰߟ͑Δ͕࣌ؒඞཁʹͳΔ͕ɺશମͷίετͷ ɺ10-20%ఔઃܭʹͬͯྑ͍ͱචऀݴ͍ͬͯΔɻ • ࠷ॳͯ͘ঃʑʹ্͕͍ͬͯ͘ •
Strategic Programming • Deep Module Λ࡞Δ • దʹϑΝΠϧΛ͚ͯɺదʹϑΝΠϧΛ ౷߹͢Δ •
ϨΠϠ͝ͱʹநԽͷํΛม͑Δ • ྫ֎Λఆٛ͢Δ
Deep Module Λ࡞Δ • நԽͷ伴ใΛ࠷খݶʹߜΔ͜ͱ • Shallow Module Έ͍ͨͳ୯ʹ࣮͕؆୯Ͱதͷബ͍Ϟδϡʔ ϧ͔ΓʹͳΔ͜ͱආ͚ͳ͚Ε͍͚ͳ͍
• ΠϯλϑΣʔεγϯϓϧʹɺ࣮खް͘ •
Deep Module Λ࡞Δ • ྫ͑ • Java I/O ΫϥεͷσβΠϯ shallow
module ʹͳ͍ͬͯΔ ͜Ε͕ࣗѱ͍ɺͱ͍͏༁Ͱͳ͍͕ όοϑΝ͢Δ͔͠ͳ͍͔͕બΔσβΠϯ
Deep Module Λ࡞Δ • ྫ͑ • ΠϯλϑΣʔεҰ൪Α͋͘ΔέʔεΛ୯७ ʹ͑ΔΑ͏ʹઃܭ͞Ε͍ͯΔ͖ • ຆͲͷϢʔβʔ͕bufferͯ͠͏͜ͱ͕جຊ
ʹͳΔͷͰ͋ΕɺͦΕ͕؆୯ʹͰ͖Δσ βΠϯͰ͋Δ͖
దʹϑΝΠϧΛ͚Δ దʹϑΝΠϧΛ౷߹͢Δ • Ͳ͜Ͱׂͯ͠Ͳ͜Ͱ౷߹͢Δ͔͕Ұ൪جຊతͳઃܭ • ౷߹͢Δͱ͖: • ใ͕ڞ༗͞ΕͯΔ࣌ (ྫ component
1 ͱ 2 ಉ͡ σʔλΛ͏) • ΠϯλϑΣʔεΛγϯϓϧʹͰ͖Δ࣌ • ॏෳΛഉআͰ͖Δ࣌
దʹϑΝΠϧΛ͚Δ దʹϑΝΠϧΛ౷߹͢Δ • ׂ͢Δ࣌ • త͕ҟͳΔ࣌: ҰൠతͳͷͱಛԽͨ͠ͷͰ͚Δɻ • ͦͷΘΓɺݺͼ͚ΔΑ͏ͳͷۃྗආ͚Δ •
ϨΠϠ͝ͱʹநԽΛม͑Δ • ϑΝΠϧγεςϜ • ϨΠϠʹHDDͷϒϩοΫ͕͋ͬͨΓɺσόΠευϥΠό͕ͦ ΕΛѻ͍ͬͯͨΓ͢Δ͕ɺߴϨΠϠͰͦΕΒΛҙࣝ͠ͳ͍Ͱѻ ͑ΔΑ͏ʹͳ͍ͬͯͨΓ͢Δɻ • ·ΕʹσʔλΛΩϟογϡ͢Δ͋ͬͨΓ͢Δɻ •
ωοτϫʔΫɾϓϩτίϧ • TCP Ͱ৴པੑͷߴ͍ϓϩτίϧΛ࡞Γͭͭͦͷ্ͰϨΠϠΛҙ ࣝ͠ͳ͍Α͏ʹͰ͖͍ͯΔ
ϨΠϠ͝ͱʹநԽΛม͑Δ • pass through ආ͚Δ • pass through ݺͼग़ͨ͠ϝιου͕ผͳϝ ιουΛͨͩݺͿ͚ͩͷߦҝ
• pass through ϝιουΛ shallow ʹͯ͠ ͠·͏
ྫ֎Λఆٛ͢Δ • ྫ֎Λग़͖͔͢ʁ͔Βߟ͑Δ • ྫ֎ΛҿΈࠐΉΈ • ͪΌΜͱྫ֎ΛͱυΩϡϝϯτʹ͢
ྫ֎Λग़͖͔͢ʁ͔Βߟ͑Δ • ྫ: Tcl ͰͷؒҧͬͨσβΠϯ • unset ͱ͍͏มͷதΛআ͢ΔΈΛݴޠʹೖΕͨʢGC͕ͳ͍͔Β ͬͨมΛআͯ͠΄͍࣌͠ͷΈʣ •
ͨͩ͠ɺະఆٛͷมΛ unset ͨ͠߹ϓϩάϥϛϯάͷόάͱͯ͠ྫ֎ Λεϩʔ͢Δઃܭʹͯ͠͠·ͬͨɻ • ݁Ռͱͯ͠ɺͲͷมΛఆ͔ٛͨ͠ΛϓϩάϥϚʔ͕͍֮͑ͯͳ͍ͱ͍͚ͳ ͘ͳͬͯ͠·ͬͨɻ • catch Ͱશ෦ͬͯ͘͘ɺҰ୴ແࢹΈ͍ͨͳΞϯνύλʔϯ͕ੜ·Εͯ͠·ͬͨ
ྫ֎Λग़͖͔͢ʁ͔Βߟ͑Δ • ྫ֎Λग़͞ͳ͍ઃܭ͋Δ • substring ϝιουʹ͍ͭͯߟ͑Δ • substring(start, end) Ͱ
end < start ͩͬͨ࣌ʹྫ ֎Λεϩʔ͢Δ͔൱͔ʁ • Java ྫ֎Λεϩʔ͢Δ͕ɺ Python ۭͷจࣈ ྻΛฦ͢
ྫ֎Λग़͖͔͢ʁ͔Βߟ͑Δ • Windows ͷϑΝΠϧγεςϜআରͷϑΝΠ ϧ͕ಡࠐதͩͬͨ࣌ʹಡΈࠐΈ͕ऴΘΔ·Ͱͭ ͱ͍͏σβΠϯɺ݁Ռͱͯ͠γεςϜશମ͕ halt ͯ͠͠·͏ • Unix
ͷϑΝΠϧγεςϜͦ͏Ͱͳ͘ɺϑΝΠ ϧΛҰ୴ಡΊΔॴʹ֬อ͔ͯ͠ΒಡΈࠐΈͱॻ ͖ग़͠ผ్ߦ͏
ྫ֎ΛҿΈࠐΉ • TCPଟগͭͳ͕Βͳ͔ͬͨΓɺྫ֎తͳঢ় گʹͳͬͨͱͯࣗ͠ͷதͰղܾ͢Δ • ϦτϥΠͨ͠ΓɺޡΓగਖ਼ͨ͠Γ͢Δ • ຊʹແཧͳঢ়گʹͳͬͨͱ͖͚ͩྫ֎Λ ্͛Δ
ྫ֎ΛҿΈࠐΉ • ͜͏͍͏ͱ͖ຊʹྫ֎తͳঢ়گͰ͋Γɺ ͦͷͱ͖Ұ୴Ϋϥογϡͤͯ͞ϦΧόϦ͢ ΔͳΓɺͳΜͳΓͷରॲΛ্ҐϨΠϠʹٻΊ Δ
ͪΌΜͱྫ֎ΛυΩϡϝϯτʹ ͢ • ͲΜͳঢ়گͷྫ֎ͳͷ͔Λ໌ه͢Δ • Կ͕ॏཁͰԿ͕ॏཁͰͳ͍͔Λॻ͔ͳ͍ͱ͍͚ ͳ͍ • ॏཁ͡Όͳ͍ྫ֎Ӆͤͳ͍͔Λݕ౼͢Δ͖ •
ॏཁͳྫ֎υΩϡϝϯτʹ໌ه͠ͳ͚Εͳ Βͳ͍
design it twice
ೋճઃܭ͠Ζ design it twice • ΤσΟλͷઃܭҰͭͱͬͯෳͷநԽͷઃܭ͕͋ΓಘΔ • ߦࢤͷΠϯλϑΣʔε • ྻࢤͷΠϯλϑΣʔε
• จࣈྻࢤͷΠϯλϑΣʔε • ҰճͷઃܭͰͯ͢ͷϝϦοτͱσϝϦοτΘ͔Βͳ͍ • ઃܭೋճͯ͠ΈΔʢ࣌ؒͷڐ͢ݶΓʣ
·ͱΊ • Tactical Programming ΊΑ͏ • Strategic Programming Λਪ •
ෳࡶ͞ґଘͱᐆດ͔͞Βى͖Δ • ෳࡶ͞มߋ૿େɺೝෛՙɺΑ͘Βͳ͍͜ͱΛ૿Ճͤ͞Δ • Strategic Programming ͜ΕΒΛߟ͑ͨ͢ΊͷҰॿͱͳΔͷ • ࢿϚΠϯυͰߟ͑ͯϓϩάϥϛϯά͢Δ