Kotlin / Kotlin/api-guidelines

Extend best-practice list: recommend using typed units instead of integer-based conversions

Open
#6 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 using typed units of measurement whenever possible.

E.g. in our official libraries we gave up on API in the form of `foo(timeMillis: Long)` and `foo(time: Long, unit: TimeUnit)` -- it's unnecessarily verbose, unclear from the call site (esp. when *callers* do not follow the naming convention), and, most importantly, is error-prone (off-by-order-of-magnitude errors). AFAIR Google even used to have a JVMLS talk about that, but all I can find is [this discussion](https://openjdk.markmail.org/thread/ndcwjnmbpwhkvkwe#query:+page:1+mid:w275uwdzjtfmiy42+state:results).

The same applies to any "easily-convertible" units -- SI, durations, bytes (kilo-/mega-) etc.

Contributor guide

Open the contributing guide

Research direction

The issue does not name a file, test, or entry point. Start by locating the best-practice list in this repository and review nearby guidance for API examples; done means adding clear guidance about typed units of measurement, including the listed duration, SI, and byte cases.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.