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
Removing Corepack
yosuke_furukawa
PRO
9
1.2k
JavaScript Runtime とはなにか
yosuke_furukawa
PRO
15
2.3k
Strip Types と Storage
yosuke_furukawa
PRO
4
320
Module Harmony について
yosuke_furukawa
PRO
3
1.5k
LTのやり方
yosuke_furukawa
PRO
16
2.1k
AppRouter Panel Talk
yosuke_furukawa
PRO
3
670
Node.js v22 で変わること
yosuke_furukawa
PRO
13
5.1k
リアーキテクトと開発生産性について
yosuke_furukawa
PRO
25
9.4k
JavaScript Server Runtime History
yosuke_furukawa
PRO
9
3.7k
Other Decks in Programming
See All in Programming
デバッグの話 / Debugging for Beginners
kaityo256
PRO
8
560
[KR] Server Driven Compose With Firebase
skydoves
2
200
What is TDD?
urakawa_jinsei
1
220
[PHPカンファレンス沖縄2024]「無理なくできるだけ安全に」テストもないレガシーコードをリファクタリングするテクニック
ikezoemakoto
3
130
선언형 UI를 학습할 때 알아둬야하는 키워드들
l2hyunwoo
0
140
モジュラモノリス、その前に / Modular monolith, before that
euglena1215
6
700
dbt-ga4パッケージを実業務に導入してみた話
t_tokumaru_feedcorp
0
130
WEBアプリケーションにおけるAWS Lambdaを用いた大規模な非同期処理の実践
delhi09
PRO
7
4.2k
Re:PandasAI:生成AIがデータ分析業務にもたらすパラダイムシフト【増補改訂版】
negi111111
1
1k
実践サーバーレスパフォーマンスチューニング ~その実力に迫る~ / Practical Serverless Performance Tuning ~A Close Look at its Power~
seike460
PRO
2
120
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
10
1.4k
MLOps in Mercari Group’s Trust and Safety ML Team
cjhj
1
120
Featured
See All Featured
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
4 Signs Your Business is Dying
shpigford
180
21k
How to name files
jennybc
77
99k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
249
21k
YesSQL, Process and Tooling at Scale
rocio
167
14k
How To Stay Up To Date on Web Technology
chriscoyier
787
250k
Fontdeck: Realign not Redesign
paulrobertlloyd
81
5.2k
How GitHub Uses GitHub to Build GitHub
holman
473
290k
Why You Should Never Use an ORM
jnunemaker
PRO
53
9k
Debugging Ruby Performance
tmm1
73
12k
Clear Off the Table
cherdarchuk
91
320k
Raft: Consensus for Rubyists
vanstee
136
6.6k
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 ͜ΕΒΛߟ͑ͨ͢ΊͷҰॿͱͳΔͷ • ࢿϚΠϯυͰߟ͑ͯϓϩάϥϛϯά͢Δ