Upgrade to Pro — share decks privately, control downloads, hide ads and more …

A Philosophy of Software Design 前半

A Philosophy of Software Design 前半

2022/02/28 に MoneyForward で発表した A Philosophy of Software Design の話です。

Yosuke Furukawa

February 28, 2022
Tweet

More Decks by Yosuke Furukawa

Other Decks in Programming

Transcript

  1. A philosophy of software design • 2018೥ʹॳ൛͕ϦϦʔε͞Ε • 2020೥ʹୈೋ൛͕ϦϦʔε͞Εͨ •

    ๜୊Ͱ͍͏ͱʮιϑτ΢ΣΞઃܭͷ఩ֶʯ https://www.amazon.co.jp/dp/B07N1XLQ7D/
  2. A philosophy of software design • ஶऀ͸δϣϯɾΦʔελʔϋ΢τ͞Μ • Stanford େֶͷίϯϐϡʔλαΠΤϯεڭत

    • Sprite OS (OS), Tcl.Tk(ϓϩάϥϛϯάݴޠ), RAMCloud (Ϋϥ΢υγεςϜ) ͳͲͳͲɺ੍ ࡞෺ଟ਺ https://web.stanford.edu/~ouster/cgi-bin/ home.php
  3. A philosophy of software design ͷݴ͍͍ͨࠜຊʹ͋Δͱ͜Ζ • ιϑτ΢ΣΞͷઃܭ͸ָ͍͠ • ७ਮͳ૑࡞աఔͷதͰύζϧͷΑ͏ʹͲ͏΍ͬͯઃܭ͢Δ͔

    Λߟ͑Δ͜ͱɺͦΕΛ࣮૷͢Δ͜ͱ͸΋ͷָ͍͘͢͜͝͠ͱ • ͜ͷ෦෼Λָ͠ΊΔΑ͏ʹͳͬͯ΄͍͠ • ٯʹݴ͏ͱΞυϗοΫʹϫʔʔ͍͖ͬͯͳΓॻ͍ͪΌ͔ͬͯ ΒςετΛॻ͍ͨΓ৭ʑޙ͔Βྑ͘͢ΔɺΈ͍ͨͳ͜ͱ͸ࠓ ͷτϨϯυͰ͸͋Δ΋ͷͷɺྑ͍૑࡞աఔʹ͸ͳ͍ͬͯͳ͍
  4. ྫ͑͹... • ͳΜͱͳ͘ͷ֤࿦ʹؕΓ͕ͪ • ϑϨʔϜϫʔΫԿΛ࢖͏ʁ • πʔϧΛͲ͏͢Δʁ • ςετͲ͏΍ͬͯॻ͘ʁ •

    Ͳ͏΍ͬͯ࡞Δ͔ͷٞ࿦ΑΓ΋લʹ͜ͷ࿩͕དྷͯ͠·͏έʔε͕༗Δɻ • ͜ͷखͷϑϨʔϜϫʔΫ΍πʔϧͷબఆ͸࣮૷ʹ͍ۙ • ܾΊͨΒʮϫʔʔͬͱॻ͘ʯࣄʹ૸Γ͕ͪ
  5. tactical programming vs strategic programming • ʮϫʔʔͬͱॻ͚ͩ͘ॻ͘ʯͱ͍͏ͷ͸͜ͷຊͰ͸ tactical programming ͱݺ͹Ε͓ͯΓɺ൱ఆ͞Ε͍ͯΔɻ

    • ·ͣͲ͏΍ͬͯෳࡶ͞Λ੾Γ෼͚Δ͔ͱݴͬͨ໰୊ͷ෼ղ ͱͦΕΛͲ͏΍ͬͯදݱ͢Δ͔ͱ͍͏ந৅ԽΛͪΌΜͱߦ ͏΂͖ͩͱ͍͏ओு • ͜ͷෳࡶ͞ͱ޲͖߹ͬͯίʔυΛॻ͘͜ͱΛʮstrategic programmingʯ ͱݺΜͰ͓Γɺͪ͜ΒΛਪ঑͍ͯ͠Δɻ
  6. ෳࡶ͞ • "Complexity is anything related to the structure of

    a software system that makes it hard to understand and modify the system." • ʮෳࡶ͞ͱ͸ιϑτ΢ΣΞγεςϜͷߏ଄ʹ ؔͯ͠ɺγεςϜͦͷ΋ͷΛཧղɾมߋ͠ʹ͘ ͍ͯ͘͠ΔԿ͔ʯͰ͋Δɻ
  7. มߋͷ֦େԽ (Change Amplification) • มߋՕॴ͕ଟ͘ͳΔ͜ͱ • ҰՕॴม͑Ε͹ࡁΈͦ͏ͳมߋ͚ͩͲɺ࣮͸ผͳՕॴ΋ ม͑ͳ͖Ό͍͚ͳ͍έʔε • ྫ͑͹ɺഎܠ৭ͷม਺Λݸʑͷϖʔδ͕͍࣋ͬͯͯɺશ

    ମΛม͑Δ࣌ʹҰݸҰݸͷϖʔδʹมߋ͕ٴΜͰ͠·͏ • ͜͏͍͏ͷ͸มߋՕॴͷӨڹΛ࠷খݶʹ͠Α͏ͱͨͨ͠ Ίʹ tactic ͳίʔυ͕ੵΈॏͳͬͯى͖Δ
  8. ෳࡶʹͳΔཧ༝ • "Complexity comes from an accumulation of dependencies and

    obscurities. (snip) As a result, it takes more code modifications to implement each new feature." • ʮෳࡶ͞͸ґଘͱᐆດ͞ͷ஝ੵ͔Β΋ͨΒ͞ ΕΔɻ݁Ռͱͯ͠কདྷͷػೳ࣮૷ͷͨΊʹΑ Γଟ͘ͷίʔυมߋ͕ඞཁʹͳΔʯ
  9. ᐆດ͞ (obscurity) • ᐆດͳίʔυͷྫ • Ұൠత͗͢Δม਺໊ (data, time, num) •

    υΩϡϝϯτʹ୯Ґ͕໌ه͞Ε͍ͯͳ͍ (width, height => pixel? inch? cm?) • Ұ؏ੑ͕ͳ͍ίʔυ • ґଘʹΑͬͯᐆດ͕͞Ҿ͖ى͜͞ΕΔέʔε΋༗Δ • ґଘͨ͠ίʔυͷதͰ৽͍͠Τϥʔ͕௥Ճ͞ΕͨΓɺڍಈͷมߋ͕ ى͖ͯ΋ͦΕ͕໌ه͞Ε͍ͯͳ͔ͬͨΓ
  10. Strategic Programming • ϫʔʔͬͱίʔυΛॻ͘ tactical programming Ͱ͸ͳ͘ɺ ෳࡶ͞ͱ޲͖߹͏ Strategic Programming

    Λਪ঑͍ͯ͠Δ • Α͋͘Δٕज़తෛ࠴͸ tactical programming ʹΑͬͯى͜Δ • Strategic Programming ʹ͸౤ࢿϚΠϯυ͕ඞཁ • ࠷଎Λ໨ࢦͯ͠ίʔυΛॻ͍ͯऴΘΒͤΑ͏ͱ͢ΔͷͰ͸ͳ ͘ɺҰ୴ෳࡶ͞ͱ޲͖߹ͬͯઃܭͷྑ͠ѱ͠Λߟ͑ͳ͕Β ίʔυΛॻ͘͜ͱ͕ॏཁ
  11. Deep Module Λ࡞Δ • ྫ͑͹ • Java I/O ΫϥεͷσβΠϯ͸ shallow

    module ʹͳ͍ͬͯΔ ͜Εࣗ਎͕ѱ͍ɺͱ͍͏༁Ͱ͸ͳ͍͕ όοϑΝ͢Δ͔͠ͳ͍͔͕બ΂ΔσβΠϯ
  12. ྫ֎Λग़͢΂͖͔ʁ͔Βߟ͑Δ • ྫ: Tcl ͰͷؒҧͬͨσβΠϯ • unset ͱ͍͏ม਺ͷத਎Λ࡟আ͢Δ࢓૊ΈΛݴޠʹೖΕͨʢGC͕ͳ͍͔Β ࢖ͬͨม਺Λ࡟আͯ͠΄͍࣌͠ͷ࢓૊Έʣ •

    ͨͩ͠ɺະఆٛͷม਺Λ unset ͨ͠৔߹͸ϓϩάϥϛϯάͷόάͱͯ͠ྫ֎ Λεϩʔ͢Δઃܭʹͯ͠͠·ͬͨɻ • ݁Ռͱͯ͠ɺͲͷม਺Λఆ͔ٛͨ͠ΛϓϩάϥϚʔ͕͍֮͑ͯͳ͍ͱ͍͚ͳ ͘ͳͬͯ͠·ͬͨɻ • catch Ͱશ෦ͬͯ͘͘ɺҰ୴ແࢹΈ͍ͨͳΞϯνύλʔϯ͕ੜ·Εͯ͠·ͬͨ
  13. ྫ֎Λग़͢΂͖͔ʁ͔Βߟ͑Δ • ྫ֎Λग़͞ͳ͍ઃܭ΋͋Δ • substring ϝιουʹ͍ͭͯߟ͑Δ • substring(start, end) Ͱ

    end < start ͩͬͨ࣌ʹྫ ֎Λεϩʔ͢Δ͔൱͔ʁ • Java ͸ྫ֎Λεϩʔ͢Δ͕ɺ Python ͸ۭͷจࣈ ྻΛฦ͢
  14. ೋճઃܭ͠Ζ design it twice • ΤσΟλͷઃܭҰͭͱͬͯ΋ෳ਺ͷந৅Խͷઃܭ͕͋ΓಘΔ • ߦࢤ޲ͷΠϯλϑΣʔε • ྻࢤ޲ͷΠϯλϑΣʔε

    • จࣈྻࢤ޲ͷΠϯλϑΣʔε • ҰճͷઃܭͰ͢΂ͯͷϝϦοτͱσϝϦοτ͸Θ͔Βͳ͍ • ઃܭ͸ೋճͯ͠ΈΔʢ࣌ؒͷڐ͢ݶΓʣ
  15. ·ͱΊ • Tactical Programming ͸΍ΊΑ͏ • Strategic Programming Λਪ঑ •

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