How to design a library

How to design a library

Богдан Сторожук.

5b8d20aa7d63c5d391b1c881e1764460?s=128

Iskander (Alex) Sharipov

April 25, 2020
Tweet

Transcript

  1. How to please everyone

  2. How to please everyone or random thoughts about library design

  3. What we will talk about

  4. What we will talk about • Design your library API

  5. What we will talk about • Design your library API

    • Make it clear, effective, predictable and transparent
  6. What we will talk about • Design your library API

    • Make it clear, effective, predictable and transparent • Choose between alternative implementations
  7. What we will talk about • Design your library API

    • Make it clear, effective, predictable and transparent • Choose between alternative implementations • Assess your choices
  8. About me

  9. About me

  10. About me

  11. About me

  12. Disclaimer This talk is based on personal experience

  13. Your users

  14. Your users •Regular users

  15. Your users •Regular users •Advanced users

  16. Your users •Regular users •Advanced users •Experts

  17. Your users •Regular users •Advanced users •Experts

  18. Your users •Regular users •Advanced users •Experts

  19. Your users •Regular users •Advanced users •Experts

  20. Regular users

  21. Regular users

  22. Regular users

  23. Regular users

  24. None
  25. None
  26. Example

  27. Example

  28. Example github.com/storozhukBM/verifier

  29. Example github.com/storozhukBM/verifier

  30. copy&paste friendliness • Meaningful method names

  31. copy&paste friendliness • Meaningful method names • Zero configuration

  32. copy&paste friendliness • Meaningful method names • Zero configuration •

    Familiar patterns
  33. copy&paste friendliness • Meaningful method names • Zero configuration •

    Familiar patterns • Testability
  34. copy&paste friendliness • Meaningful method names • Zero configuration •

    Familiar patterns • Testability • No state management
  35. Examples github.com/pkg/errors

  36. Examples github.com/robfig/cron

  37. Examples github.com/robfig/cron

  38. Examples github.com/robfig/cron

  39. Examples github.com/robfig/cron

  40. Examples github.com/robfig/cron

  41. Advanced users

  42. None
  43. Advanced users

  44. Pragmatism friendliness • Meaningful method names • Zero configuration •

    Familiar patterns • Testability • No state management
  45. Pragmatism friendliness • Meaningful method names • Zero configuration Reasonable

    defaults • Familiar patterns • Testability • No state management
  46. Pragmatism friendliness • Meaningful method names • Zero configuration Reasonable

    defaults • Familiar patterns • Testability Introspection • No state management
  47. Pragmatism friendliness • Meaningful method names • Zero configuration Reasonable

    defaults • Familiar patterns • Testability Introspection • No state management (by default)
  48. Optional configuration

  49. Optional configuration github.com/tidwall/buntdb

  50. Optional configuration github.com/tidwall/buntdb

  51. Optional configuration github.com/valyala/fasthttp

  52. Introspection

  53. Introspection github.com/valyala/fasthttp

  54. Introspection github.com/valyala/fasthttp

  55. Introspection github.com/resilience4j/resilience4j

  56. Introspection github.com/resilience4j/resilience4j

  57. Introspection github.com/resilience4j/resilience4j

  58. Introspection github.com/resilience4j/resilience4j

  59. Introspection github.com/resilience4j/resilience4j

  60. Experts

  61. Experts

  62. Experts

  63. Expert friendliness • allocations controll

  64. Expert friendliness • allocations controll • zero-cost abstractions

  65. Expert friendliness • allocations controll • zero-cost abstractions • cost

    modelling
  66. Expert friendliness • allocations controll • zero-cost abstractions • cost

    modelling • paradigm agnostics
  67. Expert friendliness • allocations controll • zero-cost abstractions • cost

    modelling • paradigm agnostics • multi-level API
  68. Tools •Profiler

  69. Tools •Profiler •Tracer

  70. Tools •Profiler •Tracer •Throughput benchmarks

  71. Tools •Profiler •Tracer •Throughput benchmarks •Latency benchmarks

  72. Tools •Profiler •Tracer •Throughput benchmarks •Latency benchmarks •Allocations profiling

  73. Allocations control github.com/storozhukBM/verifier

  74. Allocations control github.com/storozhukBM/verifier

  75. Allocations control github.com/storozhukBM/verifier

  76. Allocations control github.com/storozhukBM/verifier

  77. Zero-cost abstractions “not pay for what you don't use”

  78. Zero-cost abstractions github.com/resilience4j/resilience4j

  79. Zero-cost abstractions github.com/resilience4j/resilience4j

  80. Cost modelling

  81. None
  82. None
  83. None
  84. None
  85. Paradigm agnostics

  86. Paradigm agnostics

  87. Is it even possible? •Regular users •Advanced users •Experts

  88. None
  89. None
  90. Multi-level API

  91. Multi-level API

  92. Multi-level API

  93. Multi-level API

  94. Multi-level API

  95. One more thing

  96. None
  97. One more thing

  98. Backward compatibility

  99. API State Clear Stateless Predictable Transparent Effective Summary

  100. FIN