Kotlin / Kotlin/api-guidelines

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

Open
#7 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
154
Forks
25
Avg merge
19d 1h
Merged PRs (30d)
1

Description

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`)

Contributor guide

Open the contributing guide

Research direction

Start by locating the best-practice list in the repository and read the surrounding guidance for library API design. Use the issue's Clock.System.now(), FileSystem.DEFAULT.read*, and Dispatchers.Default examples to frame the recommendation; done means the guideline clearly explains preferring injectable, explicitly scoped state over top-level or global providers.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.