Slide 1

Slide 1 text

A philosophy of software design (લ൒) 2022/2/28 @ MoneyForward ษڧձ

Slide 2

Slide 2 text

Twitter: @yosuke_furukawa Github: yosuke-furukawa

Slide 3

Slide 3 text

A philosophy of software design • 2018೥ʹॳ൛͕ϦϦʔε͞Ε • 2020೥ʹୈೋ൛͕ϦϦʔε͞Εͨ • ๜୊Ͱ͍͏ͱʮιϑτ΢ΣΞઃܭͷ఩ֶʯ https://www.amazon.co.jp/dp/B07N1XLQ7D/

Slide 4

Slide 4 text

A philosophy of software design • ஶऀ͸δϣϯɾΦʔελʔϋ΢τ͞Μ • Stanford େֶͷίϯϐϡʔλαΠΤϯεڭत • Sprite OS (OS), Tcl.Tk(ϓϩάϥϛϯάݴޠ), RAMCloud (Ϋϥ΢υγεςϜ) ͳͲͳͲɺ੍ ࡞෺ଟ਺ https://web.stanford.edu/~ouster/cgi-bin/ home.php

Slide 5

Slide 5 text

A philosophy of software design ͷݴ͍͍ͨࠜຊʹ͋Δͱ͜Ζ • ιϑτ΢ΣΞͷઃܭ͸ָ͍͠ • ७ਮͳ૑࡞աఔͷதͰύζϧͷΑ͏ʹͲ͏΍ͬͯઃܭ͢Δ͔ Λߟ͑Δ͜ͱɺͦΕΛ࣮૷͢Δ͜ͱ͸΋ͷָ͍͘͢͜͝͠ͱ • ͜ͷ෦෼Λָ͠ΊΔΑ͏ʹͳͬͯ΄͍͠ • ٯʹݴ͏ͱΞυϗοΫʹϫʔʔ͍͖ͬͯͳΓॻ͍ͪΌ͔ͬͯ ΒςετΛॻ͍ͨΓ৭ʑޙ͔Βྑ͘͢ΔɺΈ͍ͨͳ͜ͱ͸ࠓ ͷτϨϯυͰ͸͋Δ΋ͷͷɺྑ͍૑࡞աఔʹ͸ͳ͍ͬͯͳ͍

Slide 6

Slide 6 text

ͦ΋ͦ΋ઃܭϓϩηεΛͪΌ Μͱ޻ఔͱͯ͠΍͍ͬͯΔͱ ͜Ζ͸গͳ͍

Slide 7

Slide 7 text

ྫ͑͹... • ΞδϟΠϧ։ൃ • εϓϦϯτͰ2िؒͷΰʔϧΛܾΊͯͦΕʹ޲͚ͯ ։ൃΛ͍ͯ͘͠ • ͢ΔͱͲ͏ͯ͠΋࣮૷ʹλεΫ͕ϑΥʔΧε͞ΕΔ • ݁Ռͱͯ͠࠷ॳ͔Βʮϫʔʔ࣮ͬͯ૷ͯ͠ɺޙ͔Β ςετॻ͘ʯʹͳΓ͕ͪ

Slide 8

Slide 8 text

ྫ͑͹... • ҰਓͷϑϧελοΫϓϩάϥϚʔ͚͕ͩΞαΠ ϯ͞ΕͯϓϩδΣΫτΛճ͠ଓ͚ΔΑ͏ͳঢ়گ • ԿͰ΋΍Βͳ͍ͱ͍͚ͳ͍ঢ়گʹ௥͍ࠐ·Εͯ Δ • ϫʔʔͬͱॻ͚ͩ͘ʹͳΓ͕ͪɺͱ͍͏͔ͦ ͏͡Όͳ͍ͱऴΘΒͳ͍ঢ়گʹͳͬͯΔ

Slide 9

Slide 9 text

ྫ͑͹... • ͳΜͱͳ͘ͷ֤࿦ʹؕΓ͕ͪ • ϑϨʔϜϫʔΫԿΛ࢖͏ʁ • πʔϧΛͲ͏͢Δʁ • ςετͲ͏΍ͬͯॻ͘ʁ • Ͳ͏΍ͬͯ࡞Δ͔ͷٞ࿦ΑΓ΋લʹ͜ͷ࿩͕དྷͯ͠·͏έʔε͕༗Δɻ • ͜ͷखͷϑϨʔϜϫʔΫ΍πʔϧͷબఆ͸࣮૷ʹ͍ۙ • ܾΊͨΒʮϫʔʔͬͱॻ͘ʯࣄʹ૸Γ͕ͪ

Slide 10

Slide 10 text

͜͏͍͏ʮϫʔʔͬͱॻͩ͘ ͚ॻ͘ʯͱ͍͏ϓϩάϥϛϯ άΛ൱ఆ͍ͯ͠Δ

Slide 11

Slide 11 text

tactical programming vs strategic programming • ʮϫʔʔͬͱॻ͚ͩ͘ॻ͘ʯͱ͍͏ͷ͸͜ͷຊͰ͸ tactical programming ͱݺ͹Ε͓ͯΓɺ൱ఆ͞Ε͍ͯΔɻ • ·ͣͲ͏΍ͬͯෳࡶ͞Λ੾Γ෼͚Δ͔ͱݴͬͨ໰୊ͷ෼ղ ͱͦΕΛͲ͏΍ͬͯදݱ͢Δ͔ͱ͍͏ந৅ԽΛͪΌΜͱߦ ͏΂͖ͩͱ͍͏ओு • ͜ͷෳࡶ͞ͱ޲͖߹ͬͯίʔυΛॻ͘͜ͱΛʮstrategic programmingʯ ͱݺΜͰ͓Γɺͪ͜ΒΛਪ঑͍ͯ͠Δɻ

Slide 12

Slide 12 text

ෳࡶ͞ͱ޲͖߹͏

Slide 13

Slide 13 text

ιϑτ΢ΣΞ։ൃʹ͸ෳࡶ͕͞ ͖ͭ΋ͷ • ෳࡶ͞ͷ੒ΓཱͪΛ஌Γ • ෳࡶ͞ΛͲ͏΍ͬͯॲཧ͢Δ͔Λߟ͑Δ • ͦΕ͕ͦ͜ "ઃܭ" Ͱ͋Δ

Slide 14

Slide 14 text

ͦ΋ͦ΋ෳࡶ͞ͱ͸

Slide 15

Slide 15 text

ෳࡶ͞ • "Complexity is anything related to the structure of a software system that makes it hard to understand and modify the system." • ʮෳࡶ͞ͱ͸ιϑτ΢ΣΞγεςϜͷߏ଄ʹ ؔͯ͠ɺγεςϜͦͷ΋ͷΛཧղɾมߋ͠ʹ͘ ͍ͯ͘͠ΔԿ͔ʯͰ͋Δɻ

Slide 16

Slide 16 text

ෳࡶ͞ʹΑͬͯҾ͖ى͜͞ΕΔ ঢ়ଶ • มߋͷ֦େԽ (Change Amplification) • ೝ஌ෛՙͷ૿Ճ (Cognitive Load) • ஌Βͳ͍͜ͱͷ૿Ճ (Unknown Unknowns)

Slide 17

Slide 17 text

มߋͷ֦େԽ (Change Amplification) • มߋՕॴ͕ଟ͘ͳΔ͜ͱ • ҰՕॴม͑Ε͹ࡁΈͦ͏ͳมߋ͚ͩͲɺ࣮͸ผͳՕॴ΋ ม͑ͳ͖Ό͍͚ͳ͍έʔε • ྫ͑͹ɺഎܠ৭ͷม਺Λݸʑͷϖʔδ͕͍࣋ͬͯͯɺશ ମΛม͑Δ࣌ʹҰݸҰݸͷϖʔδʹมߋ͕ٴΜͰ͠·͏ • ͜͏͍͏ͷ͸มߋՕॴͷӨڹΛ࠷খݶʹ͠Α͏ͱͨͨ͠ Ίʹ tactic ͳίʔυ͕ੵΈॏͳͬͯى͖Δ

Slide 18

Slide 18 text

มߋͷ֦େԽ (Change Amplification) ҰՕॴͰม͑ΒΕΔΑ͏ʹͳ͍ͬͯͳ͍ྫ

Slide 19

Slide 19 text

ೝ஌ෛՙͷ૿Ճ (Cognitive Load) • ୯७ʹಡΈʹ͍͘ίʔυ • ίʔυ͕ϕλοͱॻ͔Ε͍ͯͯɺؔ਺ͱ͔Ϋϥε ͱ͔ͰͪΌΜͱ෼ׂ͞Εͯͳ͔ͬͨΓɺҰՕॴͰ ৭ʑ΍Γ͗ͩͬͨ͢Γɺͦ΋ͦ΋ม਺ɾؔ਺໊͕ ௚ײͱ߹Θͳ͔ͬͨΓ • Α͘ݴΘΕͯΔΫιίʔυͬͯݺ͹ΕͨΓɺώϤ ίʔυͬͯݺ͹ΕͨΓ͢Δ΍ͭ

Slide 20

Slide 20 text

஌Βͳ͍͜ͱͷ૿Ճ (Unknown Unknowns) • ௚༁͢Δͱʮ஌Βͳ͍͜ͱʯΛ஌Βͳ͍͜ͱ • ͦͷλεΫΛऴ͑ΔͷʹͲ͜·ͰνΣοΫ͢Ε͹͍ ͍͔͕ෆ໌ྎͳ͜ͱ • มߋͨ͠Βʮ࣮͸͜͜ʹ΋Өڹ͋Γ·ͨ͠ʔʯͳࣄ ͕ӅΕͯΔ • ʮӅΕͨӨڹ㲈Α͘஌Βͳ͍͜ͱʯ͕Θ͔Βͳ͍͜ͱ

Slide 21

Slide 21 text

஌Βͳ͍͜ͱͷ૿Ճ (Unknown Unknowns) ҰՕॴͰม͑ΒΕΔΑ͏ʹͳͬͨ΋ͷͷɺ࣮͸ emphͱ͍͏ผͳछྨͷม਺Ͱݸʑʹϖʔδ৭੍͕ޚ͞Ε͍ͯΔྫ FNQI͕ VOLOPXO

Slide 22

Slide 22 text

ͳΜͰෳࡶʹͳΔͷ͔

Slide 23

Slide 23 text

ෳࡶʹͳΔཧ༝ • "Complexity comes from an accumulation of dependencies and obscurities. (snip) As a result, it takes more code modifications to implement each new feature." • ʮෳࡶ͞͸ґଘͱᐆດ͞ͷ஝ੵ͔Β΋ͨΒ͞ ΕΔɻ݁Ռͱͯ͠কདྷͷػೳ࣮૷ͷͨΊʹΑ Γଟ͘ͷίʔυมߋ͕ඞཁʹͳΔʯ

Slide 24

Slide 24 text

ґଘ (dependencies) • ґଘࣗମ͸ආ͚ΒΕͳ͍ • ϥΠϒϥϦ΁ͷґଘ • ࣗ෼ͷ࡞ͬͨผͳΫϥε΁ͷґଘ • ඞͣଘࡏ͢ΔɺΉ͠Ζແ͠Ͱ͸։ൃ͕Ͱ͖ ͳ͍

Slide 25

Slide 25 text

ґଘ (dependencies) • ॏཁͳͷ͸ґଘͦͷ΋ͷΛආ͚Δ͜ͱͰ͸ͳ ͘ɺԿͷͨΊʹґଘ͍ͯ͠Δͷ͔ɺͲ͏΍ͬͯ ґଘ͍ͯ͠Δͷ͔Λ໌֬ʹ͢Δ͜ͱ • background color ͷྫͰݴ͑͹ɺ͜ΕΛม͑ Ε͹શͯͷഎܠ৭͕มΘΔ͜ͱΛ໌֬ʹ͢Δɻ • ٯʹݴ͑͹ෆ໌ྎͳґଘ͸ආ͚Δɻ

Slide 26

Slide 26 text

ᐆດ͞ (obscurity) • ᐆດͳίʔυͷྫ • Ұൠత͗͢Δม਺໊ (data, time, num) • υΩϡϝϯτʹ୯Ґ͕໌ه͞Ε͍ͯͳ͍ (width, height => pixel? inch? cm?) • Ұ؏ੑ͕ͳ͍ίʔυ • ґଘʹΑͬͯᐆດ͕͞Ҿ͖ى͜͞ΕΔέʔε΋༗Δ • ґଘͨ͠ίʔυͷதͰ৽͍͠Τϥʔ͕௥Ճ͞ΕͨΓɺڍಈͷมߋ͕ ى͖ͯ΋ͦΕ͕໌ه͞Ε͍ͯͳ͔ͬͨΓ

Slide 27

Slide 27 text

ᐆດ͞ (obscurity) • Ұ൪ଟ͍ͷ͸ʮυΩϡϝϯτෆ଍ʯʹΑΔᐆ ດ͞ • ͳΜͰ΋υΩϡϝϯτʹॻ͚Αͱ͍͏࿩Ͱ͸ ͳ͍ɻ • γϯϓϧͳઃܭʹΑͬͯυΩϡϝϯτ͕ͦ͜ ·Ͱඞཁͳ͘ͳΔ͜ͱ΋͋Δ

Slide 28

Slide 28 text

Strategic Programming

Slide 29

Slide 29 text

Strategic Programming • ϫʔʔͬͱίʔυΛॻ͘ tactical programming Ͱ͸ͳ͘ɺ ෳࡶ͞ͱ޲͖߹͏ Strategic Programming Λਪ঑͍ͯ͠Δ • Α͋͘Δٕज़తෛ࠴͸ tactical programming ʹΑͬͯى͜Δ • Strategic Programming ʹ͸౤ࢿϚΠϯυ͕ඞཁ • ࠷଎Λ໨ࢦͯ͠ίʔυΛॻ͍ͯऴΘΒͤΑ͏ͱ͢ΔͷͰ͸ͳ ͘ɺҰ୴ෳࡶ͞ͱ޲͖߹ͬͯઃܭͷྑ͠ѱ͠Λߟ͑ͳ͕Β ίʔυΛॻ͘͜ͱ͕ॏཁ

Slide 30

Slide 30 text

౤ࢿϚΠϯυ • ྑ͍ઃܭ͸ແྉͰ࡞Εͳ͍ • ແྉͰ͸ͳ͍ͷͰߟ͑Δ͕࣌ؒඞཁʹͳΔ͕ɺશମͷίετͷ ಺ɺ10-20%ఔ౓͸ઃܭʹ࢖ͬͯྑ͍ͱචऀ͸ݴ͍ͬͯΔɻ • ࠷ॳ͸஗ͯ͘΋ঃʑʹ্͕͍ͬͯ͘ •

Slide 31

Slide 31 text

Strategic Programming • Deep Module Λ࡞Δ • ద੾ʹϑΝΠϧΛ෼͚ͯɺద੾ʹϑΝΠϧΛ ౷߹͢Δ • ϨΠϠ͝ͱʹந৅Խͷํ਑Λม͑Δ • ྫ֎Λఆٛ͢Δ

Slide 32

Slide 32 text

Deep Module Λ࡞Δ • ந৅Խͷ伴͸৘ใΛ࠷খݶʹߜΔ͜ͱ • Shallow Module Έ͍ͨͳ୯ʹ࣮૷͕؆୯Ͱத਎ͷബ͍Ϟδϡʔ ϧ͹͔ΓʹͳΔ͜ͱ͸ආ͚ͳ͚Ε͹͍͚ͳ͍ • ΠϯλϑΣʔε͸γϯϓϧʹɺ࣮૷͸खް͘ •

Slide 33

Slide 33 text

Deep Module Λ࡞Δ • ྫ͑͹ • Java I/O ΫϥεͷσβΠϯ͸ shallow module ʹͳ͍ͬͯΔ ͜Εࣗ਎͕ѱ͍ɺͱ͍͏༁Ͱ͸ͳ͍͕ όοϑΝ͢Δ͔͠ͳ͍͔͕બ΂ΔσβΠϯ

Slide 34

Slide 34 text

Deep Module Λ࡞Δ • ྫ͑͹ • ΠϯλϑΣʔε͸Ұ൪Α͋͘ΔέʔεΛ୯७ ʹ࢖͑ΔΑ͏ʹઃܭ͞Ε͍ͯΔ΂͖ • ຆͲͷϢʔβʔ͕bufferͯ͠࢖͏͜ͱ͕جຊ ʹͳΔͷͰ͋Ε͹ɺͦΕ͕؆୯ʹͰ͖Δσ βΠϯͰ͋Δ΂͖

Slide 35

Slide 35 text

ద੾ʹϑΝΠϧΛ෼͚Δ ద੾ʹϑΝΠϧΛ౷߹͢Δ • Ͳ͜Ͱ෼ׂͯ͠Ͳ͜Ͱ౷߹͢Δ͔͕Ұ൪جຊతͳઃܭ • ౷߹͢Δͱ͖: • ৘ใ͕ڞ༗͞ΕͯΔ࣌ (ྫ component 1 ͱ 2 ͸ಉ͡ σʔλΛ࢖͏) • ΠϯλϑΣʔεΛγϯϓϧʹͰ͖Δ࣌ • ॏෳΛഉআͰ͖Δ࣌

Slide 36

Slide 36 text

ద੾ʹϑΝΠϧΛ෼͚Δ ద੾ʹϑΝΠϧΛ౷߹͢Δ • ෼ׂ͢Δ࣌ • ໨త͕ҟͳΔ࣌: Ұൠతͳ΋ͷͱಛԽͨ͠΋ͷͰ෼͚Δɻ • ͦͷ୅ΘΓɺݺͼ෼͚ΔΑ͏ͳͷ͸ۃྗආ͚Δ •

Slide 37

Slide 37 text

ϨΠϠ͝ͱʹந৅ԽΛม͑Δ • ϑΝΠϧγεςϜ • ௿ϨΠϠʹ͸HDDͷϒϩοΫ͕͋ͬͨΓɺσόΠευϥΠό͕ͦ ΕΛѻ͍ͬͯͨΓ͢Δ͕ɺߴϨΠϠͰ͸ͦΕΒΛҙࣝ͠ͳ͍Ͱѻ ͑ΔΑ͏ʹͳ͍ͬͯͨΓ͢Δɻ • ·ΕʹσʔλΛΩϟογϡ͢Δ૚΋͋ͬͨΓ͢Δɻ • ωοτϫʔΫɾϓϩτίϧ • TCP Ͱ৴པੑͷߴ͍ϓϩτίϧΛ࡞Γͭͭͦͷ্Ͱ͸ϨΠϠΛҙ ࣝ͠ͳ͍Α͏ʹͰ͖͍ͯΔ

Slide 38

Slide 38 text

ϨΠϠ͝ͱʹந৅ԽΛม͑Δ • pass through ͸ආ͚Δ • pass through ݺͼग़ͨ͠ϝιου͕ผͳϝ ιουΛͨͩݺͿ͚ͩͷߦҝ • pass through ͸ϝιουΛ shallow ʹͯ͠ ͠·͏

Slide 39

Slide 39 text

ྫ֎Λఆٛ͢Δ • ྫ֎Λग़͢΂͖͔ʁ͔Βߟ͑Δ • ྫ֎ΛҿΈࠐΉ࢓૊Έ • ͪΌΜͱྫ֎ΛͱυΩϡϝϯτʹ࢒͢

Slide 40

Slide 40 text

ྫ֎Λग़͢΂͖͔ʁ͔Βߟ͑Δ • ྫ: Tcl ͰͷؒҧͬͨσβΠϯ • unset ͱ͍͏ม਺ͷத਎Λ࡟আ͢Δ࢓૊ΈΛݴޠʹೖΕͨʢGC͕ͳ͍͔Β ࢖ͬͨม਺Λ࡟আͯ͠΄͍࣌͠ͷ࢓૊Έʣ • ͨͩ͠ɺະఆٛͷม਺Λ unset ͨ͠৔߹͸ϓϩάϥϛϯάͷόάͱͯ͠ྫ֎ Λεϩʔ͢Δઃܭʹͯ͠͠·ͬͨɻ • ݁Ռͱͯ͠ɺͲͷม਺Λఆ͔ٛͨ͠ΛϓϩάϥϚʔ͕͍֮͑ͯͳ͍ͱ͍͚ͳ ͘ͳͬͯ͠·ͬͨɻ • catch Ͱશ෦ͬͯ͘͘ɺҰ୴ແࢹΈ͍ͨͳΞϯνύλʔϯ͕ੜ·Εͯ͠·ͬͨ

Slide 41

Slide 41 text

ྫ֎Λग़͢΂͖͔ʁ͔Βߟ͑Δ • ྫ֎Λग़͞ͳ͍ઃܭ΋͋Δ • substring ϝιουʹ͍ͭͯߟ͑Δ • substring(start, end) Ͱ end < start ͩͬͨ࣌ʹྫ ֎Λεϩʔ͢Δ͔൱͔ʁ • Java ͸ྫ֎Λεϩʔ͢Δ͕ɺ Python ͸ۭͷจࣈ ྻΛฦ͢

Slide 42

Slide 42 text

ྫ֎Λग़͢΂͖͔ʁ͔Βߟ͑Δ • Windows ͷϑΝΠϧγεςϜ͸࡟আର৅ͷϑΝΠ ϧ͕ಡࠐதͩͬͨ࣌ʹಡΈࠐΈ͕ऴΘΔ·Ͱ଴ͭ ͱ͍͏σβΠϯɺ݁Ռͱͯ͠γεςϜશମ͕ halt ͯ͠͠·͏ • Unix ͷϑΝΠϧγεςϜ͸ͦ͏Ͱ͸ͳ͘ɺϑΝΠ ϧΛҰ୴ಡΊΔ৔ॴʹ֬อ͔ͯ͠ΒಡΈࠐΈͱॻ ͖ग़͠͸ผ్ߦ͏

Slide 43

Slide 43 text

ྫ֎ΛҿΈࠐΉ • TCP͸ଟগͭͳ͕Βͳ͔ͬͨΓɺྫ֎తͳঢ় گʹͳͬͨͱͯ͠΋ࣗ෼ͷதͰղܾ͢Δ • ϦτϥΠͨ͠ΓɺޡΓగਖ਼ͨ͠Γ͢Δ • ຊ౰ʹແཧͳঢ়گʹͳͬͨͱ͖͚ͩྫ֎Λ ্͛Δ

Slide 44

Slide 44 text

ྫ֎ΛҿΈࠐΉ • ͜͏͍͏ͱ͖͸ຊ౰ʹྫ֎తͳঢ়گͰ͋Γɺ ͦͷͱ͖͸Ұ୴Ϋϥογϡͤͯ͞ϦΧόϦ͢ ΔͳΓɺͳΜͳΓͷରॲΛ্ҐϨΠϠʹٻΊ Δ

Slide 45

Slide 45 text

ͪΌΜͱྫ֎ΛυΩϡϝϯτʹ ࢒͢ • ͲΜͳঢ়گͷྫ֎ͳͷ͔Λ໌ه͢Δ • Կ͕ॏཁͰԿ͕ॏཁͰͳ͍͔Λॻ͔ͳ͍ͱ͍͚ ͳ͍ • ॏཁ͡Όͳ͍ྫ֎͸Ӆͤͳ͍͔Λݕ౼͢Δ΂͖ • ॏཁͳྫ֎͸υΩϡϝϯτʹ໌ه͠ͳ͚Ε͹ͳ Βͳ͍

Slide 46

Slide 46 text

design it twice

Slide 47

Slide 47 text

ೋճઃܭ͠Ζ design it twice • ΤσΟλͷઃܭҰͭͱͬͯ΋ෳ਺ͷந৅Խͷઃܭ͕͋ΓಘΔ • ߦࢤ޲ͷΠϯλϑΣʔε • ྻࢤ޲ͷΠϯλϑΣʔε • จࣈྻࢤ޲ͷΠϯλϑΣʔε • ҰճͷઃܭͰ͢΂ͯͷϝϦοτͱσϝϦοτ͸Θ͔Βͳ͍ • ઃܭ͸ೋճͯ͠ΈΔʢ࣌ؒͷڐ͢ݶΓʣ

Slide 48

Slide 48 text

·ͱΊ • Tactical Programming ͸΍ΊΑ͏ • Strategic Programming Λਪ঑ • ෳࡶ͞͸ґଘͱᐆດ͔͞Βى͖Δ • ෳࡶ͞͸มߋ૿େɺೝ஌ෛՙɺΑ͘஌Βͳ͍͜ͱΛ૿Ճͤ͞Δ • Strategic Programming ͸͜ΕΒΛߟ͑௚ͨ͢ΊͷҰॿͱͳΔ΋ͷ • ౤ࢿϚΠϯυͰߟ͑ͯϓϩάϥϛϯά͢Δ