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

モジュールの深さについて / depth of module

nakabonne
January 28, 2019

モジュールの深さについて / depth of module

nakabonne

January 28, 2019
Tweet

More Decks by nakabonne

Other Decks in Technology

Transcript

  1. Ϟδϡʔϧͷਂ͞ʹ͍ͭͯ
    CAEC MeetUP #4

    View Slide

  2. Me
    • தඌ ྋ (@nakabonne)
    • தԝେֶ঎ֶ෦3೥
    • AWAϚΠΫϩαʔϏε
    • Go, Envoy, etc…

    View Slide

  3. My tasks
    https://www.redhat.com/cms/managed-files/service-mesh-1680.png

    View Slide

  4. My tasks
    https://github.com/DataDog/dd-py-tracing-workshop

    View Slide

  5. Agenda
    • ྑ͍Ϟδϡʔϧͱ͸
    • deep moduleͱ͸

    View Slide

  6. ྑ͍Ϟδϡʔϧͱ͸

    View Slide

  7. খ͍͞Ϟδϡʔϧʁ

    View Slide

  8. –The Unix Philosophy
    “Small is beautiful”

    View Slide

  9. ԿނϞδϡʔϧΛ࡞Δͷ͔

    View Slide

  10. ؔ࿈ੑͷߴ͍ཁૉ͕ू·Δ
    →࣮૷ͷෳࡶ͞ΛԼ͛Δ

    View Slide

  11. Open a file in Java
    FileInputStream fileStream =
    new FileInputStream(fileName);
    BufferedInputStream bufferedStream =
    new BufferedInputStream(fileStream);
    ObjectInputStream objectStream =
    new ObjectInputStream(bufferedStream);

    View Slide

  12. Open a file in Java
    FileInputStream fileStream =
    new FileInputStream(fileName);
    BufferedInputStream bufferedStream =
    new BufferedInputStream(fileStream);
    ObjectInputStream objectStream =
    new ObjectInputStream(bufferedStream);
    ॳาతͳI/O

    View Slide

  13. Open a file in Java
    FileInputStream fileStream =
    new FileInputStream(fileName);
    BufferedInputStream bufferedStream =
    new BufferedInputStream(fileStream);
    ObjectInputStream objectStream =
    new ObjectInputStream(bufferedStream);
    όοϑΝϦϯά

    View Slide

  14. Open a file in Java
    FileInputStream fileStream =
    new FileInputStream(fileName);
    BufferedInputStream bufferedStream =
    new BufferedInputStream(fileStream);
    ObjectInputStream objectStream =
    new ObjectInputStream(bufferedStream);
    read/write

    View Slide

  15. ࣮૷ͷෳࡶ͕͞࿙ΕͯΔ…

    View Slide

  16. • খ͍͞ͱ͍͏͜ͱ͸ɺ࣋ͬͯΔ৘ใྔ͕গͳ͍
    • ࣋ͬͯΔ৘ใྔ͕গͳ͍ͱɺ࣮૷ͷෳࡶ͕͞࿙
    Ε΍͍͢
    • ࣮૷ͷෳࡶ͕͞࿙Ε͍ͯΔͱɺ࣮૷มߋ͕पΓ
    ʹӨڹΛ༩͑΍͘͢ͳΔ

    View Slide

  17. খ͞͞Λҙࣝ͗͢͠Δ

    View Slide

  18. খ͞͞Λҙࣝ͗͢͠Δ

    View Slide

  19. ߴڽूʁૄ݁߹ʁ

    View Slide

  20. ߴڽूʁૄ݁߹ʁ

    View Slide

  21. ߴڽूʁૄ݁߹ʁ
    ྑ͍ΠϯλʔϑΣʔε͕ඞཁ

    View Slide

  22. ྑ͍ΠϯλʔϑΣʔεͱ͸

    View Slide

  23. Bad interface

    View Slide

  24. Bad interface

    View Slide

  25. Bad interface

    View Slide

  26. ͔͠͠ιϑτ΢ΣΞ͸มߋ͞ΕΔ
    →͜ͷໃ६ͷதͰ΋่Εͳ͍͜ͱ͕ٻΊΒΕΔ

    View Slide

  27. Good interface
    ෆมʢ௥ՃҎ֎ͷมߋΛڐ͞ͳ͍ʣ

    View Slide

  28. And

    View Slide

  29. ࢖͍΍͋͘͢Δ΂͖

    View Slide

  30. –Rich Hickey
    “Easy is relative”

    View Slide

  31. Կ͕ศར͔͸ϢʔβʔʹΑΔ

    View Slide

  32. Use case
    Edge case
    General case

    View Slide

  33. Use case
    Edge case
    General case

    View Slide

  34. Ұൠతͳέʔεʹߜͬͯ
    ࢖͍΍͢͞Λ௥ٻ͢Δ

    View Slide

  35. ෳࡶԽͷཧ༝
    FileInputStream fileStream =
    new FileInputStream(fileName);
    BufferedInputStream bufferedStream =
    new BufferedInputStream(fileStream);
    ObjectInputStream objectStream =
    new ObjectInputStream(bufferedStream);
    όοϑΝϦϯά͠ͳ͍ͱ͍͏
    ΤοδέʔεΛڐ༰͍ͯ͠Δ

    View Slide

  36. Good module
    ؔ࿈ੑͷߴ͍ͨ͘͞ΜͷཁૉΛӅ࣋ͪ͠ɺ
    ҰൠతͳέʔεͰ࢖͍΍͘͢ෆมͳΠϯλʔ
    ϑΣʔεʹΑͬͯڧྗͳػೳΛఏڙ͢Δ

    View Slide

  37. ߟ͑Δ͜ͱଟ͗͢ʂ

    View Slide

  38. ຊ୊

    View Slide

  39. deep module

    View Slide

  40. A Philosophy of Software Design
    • ஶऀ͸ελϯϑΥʔυେֶ
    John Ousterhoutڭत
    • ઐ໳͸෼ࢄγεςϜ΍OS
    ͳͲଟذʹ౉Δ

    View Slide

  41. deep module
    γϯϓϧͳΠϯλʔϑΣʔεͰ
    ڧྗͳػೳΛఏڙ͢Δ

    View Slide

  42. deep vs shallow modules

    View Slide

  43. deep vs shallow modules

    View Slide

  44. ΠϯλʔϑΣʔεͷෳࡶ͞͸ίετͰ
    ػೳͷڧྗ͞͸རӹ

    View Slide

  45. ࢹ఺
    • ػೳ͸ڧྗ͚ͩͲɺͦΕҎ্ʹΠϯλʔ
    ϑΣʔε͕ෳࡶʹͳͬͯͳ͍͔ʁ
    • ΠϯλʔϑΣʔε͸؆୯͚ͩͲɺػೳ
    ͸ශऑͰ͸ͳ͍͔ʁ

    View Slide

  46. ྫɿUnix ϑΝΠϧI/O
    • open()
    • read()
    • write()
    • close()
    • lseek()
    ←ෆม

    View Slide

  47. Χʔωϧ
    ϢʔβΞϓϦέʔγϣϯΛ҆ఆͯ͠
    ಈ࡞ͤ͞ΔͨΊʹઃܭ͞Ε͍ͯΔ
    →ࢀߟʹͳΔ

    View Slide

  48. ·ͱΊ

    View Slide

  49. ·ͱΊ
    • ྑ͍Ϟδϡʔϧͱ͸ʮؔ࿈ੑͷߴ͍ͨ͘͞ΜͷཁૉΛӅ࣋ͪ͠ɺҰൠత
    ͳέʔεͰ࢖͍΍͘͢ෆมͳΠϯλʔϑΣʔεʹΑͬͯڧྗͳػೳΛఏ
    ڙ͢Δ΋ͷʯ
    • ࣮ݱ͢ΔͨΊʹʮϞδϡʔϧͷਂ͞ʯΛҙࣝ͢Δ
    • ͋͘·ͰҰͭͷߟ͑ํͰ͋ΔͨΊɺ൓࿦΢ΣϧΧϜ

    View Slide

  50. ͋Γ͕ͱ͏͍͟͝·ͨ͠

    View Slide