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

A Philosophy of Software Design 後半

A Philosophy of Software Design 後半

2022/6/22 @ MoneyForward 勉強会 で実施した A Philosophy of Software Design の話です。

Yosuke Furukawa

June 22, 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 લ൒·ͱΊ • Tactical Programming ͸΍ΊΑ͏

    • Strategic Programming Λਪ঑ • ෳࡶ͞͸ґଘͱᐆດ͔͞Βى͖Δ • ෳࡶ͞͸มߋ૿େɺೝ஌ෛՙɺΑ͘஌Βͳ͍͜ͱΛ૿Ճͤ͞Δ • Strategic Programming ͸͜ΕΒΛߟ͑௚ͨ͢ΊͷҰॿͱͳΔ΋ͷ • ౤ࢿϚΠϯυͰߟ͑ͯϓϩάϥϛϯά͢Δ • ԿͳΒೋճઃܭͯ͠ΈΖɺͦ͏͢Ε͹ྑ͍ઃܭ͕Ͱ͖ΔΑ͏ʹͳΔ
  4. Don't Repeat the Code ͷݪଇ • ίʔυʹॻ͍ͯ͋Δ͜ͱΛͨͩͦͷ··ίϝ ϯτʹॻ͘͜ͱΛ͠ͳ͍ // Add

    a horizontal scroll bar hScrollBar = new JScrollBar(JScrollBar.HORIZONTAL); add(hScrollBar, BorderLayout.SOUTH); // Add a vertical scroll bar vScrollBar = new JScrollBar(JScrollBar.VERTICAL); add(vScrollBar, BorderLayout.EAST); // Initialize the caret-position related values caretX = 0; caretY = 0; caretMemX = null;
  5. Don't Repeat the Code ͷݪଇ • ίʔυʹॻ͍ͯ͋Δ͜ͱΛͨͩͦͷ··ίϝ ϯτʹॻ͘͜ͱΛ͠ͳ͍ // Add

    a horizontal scroll bar hScrollBar = new JScrollBar(JScrollBar.HORIZONTAL); add(hScrollBar, BorderLayout.SOUTH); // Add a vertical scroll bar vScrollBar = new JScrollBar(JScrollBar.VERTICAL); add(vScrollBar, BorderLayout.EAST); // Initialize the caret-position related values caretX = 0; caretY = 0; caretMemX = null; ͜͏͍͏ίʔυΛݟͨΒٯʹո͠Ή
  6. ΠϯλϑΣʔεͷίϝϯτ • ࢖͍ํ΍࢖͏্Ͱͷ஫ҙࣄ߲͕ॻ͍ͯ͋Δ /* HTTP ͷαʔόͱΫϥΠΞϯτͷ࣮૷Λఏڙ͢ΔΠϯλϑΣʔε Get, Head, Post ͳͲͷ

    HTTP ϦΫΤετΛૹΔ৔߹ɺԼهͷํ๏ͰૹΔ resp, err := http.Get("http://example.com/") ... listenAndServeؔ਺Λ࣮ߦͨ͠ࡍʹطʹಉ͡ϙʔτΛlisten͍ͯͨ͠৔߹ FatalΤϥʔͱͳΓɺىಈʹࣦഊ͢Δɻ */
  7. ࣮૷ͷίϝϯτ • ΤϥʔճආͷͨΊͷϫʔΫΞϥ΢ϯυ (Why) try { } catch(e) { //

    ຊདྷ͜͜ͰΩϟον͢Δ΂͖Ͱ͸ͳ͍͕ϥΠϒϥϦ͕ xxx Error Λ // throw ͢ΔͨΊɺҰ࣌తʹΩϟον͠ɺਖ਼ৗॲཧʹ໭͢ɻ // ຊମ΁ͷ Issue 12345 ͕औΓࠐ·ΕͨΒຊॲཧ͸ෆཁ }
  8. ࣮૷ͷίϝϯτ • ҰൃͰԿ΍ͬͯΔ͔Θ͔Βͳ͍࣌ͷղઆ // ೋ࣍ݩ഑ྻͷ֤഑ྻ͝ͱͷฏۉ஋ΛऔΔ let mut averages = vec![];

    for col in 0..len { let mut sum = 0; for row in 0..nums[col].len() { sum += nums[col][row]; } averages.push(sum / nums[col].len()); }
  9. ίϝϯτ͍ͭॻ͔͘࿦૪ • ޙʹ׳Ε͹ͳΔ΄Ͳਏ͘ͳΔΜ͔ͩΒࠓॻ͜͏ • චऀ͸ίϝϯτΛॻ͍ͯΔͱ͖͕Ұ൪ָ͍࣌ͩ͠ͱࢥ͍ͬͯ Δͱͷ͜ͱ • ୺తͰ໌շͳίϝϯτ͕ॻ͚ͨ ≒ ઃܭ͕͏·͘ݴͬͯΔূڌ

    • ٯʹ্ख͘ίϝϯτ͕ॻ͚ͳ͍ͱ͍͏͜ͱ͸ઃܭ͕͏·͘ ߦͬͯͳ͍ͷ͔΋͠Εͳ͍ • ͜͏͍͏ࢥ͍Λ࣋ͪͳ͕ΒίϝϯτΛָ͠ΜͰॻ͖·͠ΐ͏
  10. ίϝϯτ͍ͭॻ͔͘࿦૪ • ޙʹ׳Ε͹ͳΔ΄Ͳਏ͘ͳΔΜ͔ͩΒࠓॻ͜͏ • චऀ͸ίϝϯτΛॻ͍ͯΔͱ͖͕Ұ൪ָ͍࣌ͩ͠ͱࢥ͍ͬͯ Δͱͷ͜ͱ • ୺తͰ໌շͳίϝϯτ͕ॻ͚ͨ ≒ ઃܭ͕͏·͘ݴͬͯΔূڌ

    • ٯʹ্ख͘ίϝϯτ͕ॻ͚ͳ͍ͱ͍͏͜ͱ͸ઃܭ͕͏·͘ ߦͬͯͳ͍ͷ͔΋͠Εͳ͍ • ͜͏͍͏ࢥ͍Λ࣋ͪͳ͕ΒίϝϯτΛָ͠ΜͰॻ͖·͠ΐ͏
  11. طଘίʔυͷमਖ਼ • ࠷ॳ͔Βਖ਼͍͠σβΠϯͷ΋ͷ͸ଘࡏ͠ͳ͍ • ண࣮ʹमਖ਼͍ͯ͘͠ඞཁ͕͋Δ • adhoc ʹ tactical ͳίʔυΛॻ͘ͷͰ͸ͳ͘ɺ

    strategic ʹ ઃܭΛͪΌΜͱ͠ͳ͕ΒίʔυΛॻ͖ɺͦΕΛܧଓ͢Δ • ίʔυίϝϯτ΋ͳΔ΂ͪ͘ΌΜͱॻ͘ • ίϝϯτ͸ந৅Խͨ͠΋ͷ΋༻ҙ͠ɺσβΠϯυΩϡϝϯτ ͳͲʹ΋൓ө͓͖ͯ͠ɺͲ͔͜ΒͰ΋ݟΕΔΑ͏ʹ͓ͯ͘͠