Kotlin / api-guidelines

Best practices to consider when writing an API for your library
https://kotl.in/api-guide
Apache License 2.0
145 stars 20 forks source link

Extend best-practice list: avoid using static "global mockable state" providers/top-level functions in the favour of injectable ones #7

Open qwwdfsad opened 1 year ago

qwwdfsad commented 1 year ago

It would be nice to recommend avoiding using "global" state in the libraries, that later is almost impossible to test and/or mock.

We tend to favor explicitly spelled-out APIs for the such state: datetime's Clock.System.now(), Okio's FileSystem.DEFAULT.read* as opposed to top-level now(), read(path) etc. (the most notable existing API that falls into this trap is coroutine's Dispatchers.Default)