Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the KDoc #367

Merged
merged 35 commits into from
May 13, 2024
Merged

Improve the KDoc #367

merged 35 commits into from
May 13, 2024

Conversation

dkhalanskyjb
Copy link
Collaborator

@dkhalanskyjb dkhalanskyjb commented Mar 12, 2024

Fixes #347

Not requesting the review initially, because I myself need to look at it with fresh eyes in a couple of days, but if someone's in the mood, they can point out the issues already. EDIT: after one more pass on my own, I've requested a review.

Copy link
Member

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tremendous and solid work

core/common/src/Clock.kt Show resolved Hide resolved
core/common/src/Clock.kt Show resolved Hide resolved
core/common/src/Clock.kt Show resolved Hide resolved
core/common/src/Clock.kt Show resolved Hide resolved
core/common/src/DateTimePeriod.kt Show resolved Hide resolved
core/common/src/DateTimeUnit.kt Show resolved Hide resolved
core/common/src/Clock.kt Show resolved Hide resolved
core/common/src/Instant.kt Outdated Show resolved Hide resolved
core/common/src/Instant.kt Show resolved Hide resolved
core/common/src/Instant.kt Show resolved Hide resolved
Copy link
Member

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A small batch from the stash

core/common/src/Clock.kt Show resolved Hide resolved
core/common/src/Clock.kt Outdated Show resolved Hide resolved
core/common/src/Instant.kt Show resolved Hide resolved
core/common/src/DateTimePeriod.kt Outdated Show resolved Hide resolved
core/common/src/DateTimePeriod.kt Show resolved Hide resolved
core/common/src/Clock.kt Outdated Show resolved Hide resolved
core/common/src/Clock.kt Outdated Show resolved Hide resolved
* ```
*
* [parse] and [toString] methods can be used to obtain a [DateTimePeriod] from and convert it to a string in the
* ISO 8601 extended format.
Copy link

@kevincianfarini kevincianfarini Apr 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way we can link to the ISO 8601 spec section which outlines time intervals?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, is it worth calling out what revision of ISO 8601 we're adhering to in every KDoc? For example, I previously misunderstood that LocalTime should support 24:00 because it was included in ISO 8601:2004(E) , but I found out it was removed in later revisions of the spec. Being specific about what revision we support could help remove ambiguity.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can only mention the relevant ISO 8601 section, but not link to it, because the standard is not in public access.

core/common/src/LocalDate.kt Outdated Show resolved Hide resolved
core/common/src/LocalDate.kt Show resolved Hide resolved
core/common/test/samples/TimeZoneSamples.kt Show resolved Hide resolved
core/common/src/format/DateTimeFormat.kt Show resolved Hide resolved
Copy link
Member

@ilya-g ilya-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The first part of comments

core/common/src/Clock.kt Outdated Show resolved Hide resolved
core/common/src/Clock.kt Show resolved Hide resolved
Comment on lines 77 to 78
* **Pitfall**: using this function with [Clock.System] is error-prone,
* because [Clock.System] is not well suited for measuring time intervals.
* Please only use this conversion function on the [Clock] instances that are fully controlled programmatically.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good to describe specifics of a time source obtained from a clock, but I wouldn't call this error prone and would avoid giving this recommendation "Please only use this conversion function on the [Clock] instances that are fully controlled programmatically."

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What other valid use cases do you see for this function? Related: #372

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, tracking timeouts tied to the wall clock. TimeMarks obtained from Instants can potentially be persistable between program runs, however we may currently lack the API to achieve that.

core/common/src/DateTimePeriod.kt Outdated Show resolved Hide resolved
core/common/src/DateTimePeriod.kt Outdated Show resolved Hide resolved
core/common/src/DateTimePeriod.kt Outdated Show resolved Hide resolved
core/common/src/DateTimePeriod.kt Outdated Show resolved Hide resolved
core/common/src/DateTimePeriod.kt Outdated Show resolved Hide resolved
Comment on lines 38 to 39
* [DateTimePeriod] is a combination of all [DateTimeUnit] values, used to express things like
* "two days and three hours."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be unclear what "all [DateTimeUnit] values" means given that we declare many date-time units and there can also be arbitrary user-defined ones.

core/common/src/DateTimeUnit.kt Outdated Show resolved Hide resolved
core/common/src/DateTimeUnit.kt Outdated Show resolved Hide resolved
core/common/src/DateTimeUnit.kt Outdated Show resolved Hide resolved
*
* For values very far in the past or the future, this conversion may fail.
* The specific range of values that can be converted to [LocalDateTime] is platform-specific, but at least
* [DISTANT_PAST], [DISTANT_FUTURE], and all values between them can be converted to [LocalDateTime].
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another way to say it is "all values in the range [DISTANT_PAST]..[DISTANT_FUTURE]", up to your decision.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like things like a..b to be between backticks so that .. is not treated as just some broken punctuation, but then, we can't have references to entities.
@qwwdfsad, IIRC, you're collecting feature requests for the KDoc syntax—navigable links in code blocks and inline code would be nice.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kotlin/dokka#3571

Don't hesitate to file it in Dokka with kdoc-spec label

core/common/src/LocalDateTime.kt Outdated Show resolved Hide resolved
core/common/src/LocalDateTime.kt Outdated Show resolved Hide resolved
core/common/src/LocalDateTime.kt Outdated Show resolved Hide resolved
core/common/src/LocalDateTime.kt Outdated Show resolved Hide resolved
core/common/src/DateTimePeriod.kt Outdated Show resolved Hide resolved
Copy link
Member

@qwwdfsad qwwdfsad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

* ### Platform specifics
*
* On the JVM,
* there are `LocalTime.toJavaLocalTime()` and `java.time.LocalTime.toKotlinLocalTime()` extension functions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to mention for what are these extensions. (same for other entities for which we provide conversions)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tough for me to think of a good way to say this without being tautological, but I tried. Is this what you meant?

@@ -49,9 +103,15 @@ public expect class LocalTime : Comparable<LocalTime> {
* @throws IllegalArgumentException if [secondOfDay] is outside the `0 until 86400` range,
* with 86400 being the number of seconds in a calendar day.
*
* It is incorrect to pass the number of seconds since the start of the day to this function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Together with the summary, it makes the impression that this function is inherently incorrect.

I believe that we should describe the model this entity represents and its discrepancies once in the class docs, and then refer to it instead of providing such note on each operation

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, the wording here is misleading. I tried correcting it.

core/common/src/UtcOffset.kt Outdated Show resolved Hide resolved
core/common/src/format/LocalDateFormat.kt Outdated Show resolved Hide resolved
@dkhalanskyjb dkhalanskyjb requested a review from ilya-g May 3, 2024 09:31
core/common/test/samples/DateTimePeriodSamples.kt Outdated Show resolved Hide resolved
core/common/test/samples/DateTimePeriodSamples.kt Outdated Show resolved Hide resolved
core/common/test/samples/DateTimePeriodSamples.kt Outdated Show resolved Hide resolved
core/common/test/samples/DateTimePeriodSamples.kt Outdated Show resolved Hide resolved
core/common/src/Instant.kt Outdated Show resolved Hide resolved
@Test
fun plusDuration() {
// Finding a moment that's later than the starting point by the given amount of real time
val instant = Instant.fromEpochMilliseconds(epochMilliseconds = 7 * 60 * 60 * 1000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more understandable to use instants obtained from parse and show the result as toString for arithmetic operation samples.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using fromEpochMilliseconds also serves to highlight the difference between Instant and LocalDateTime values. Newcomers are often confused by the distinction between them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear that overreliance on from/toEpochMilliseconds in samples would convey the wrong idea that Instant is completely defined by that number of milliseconds.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with fromEpochSeconds/epochSeconds + nanosecondsOfSecond.

core/common/test/samples/InstantSamples.kt Show resolved Hide resolved
repeat(100) {
val instant1 = randomInstant()
val instant2 = randomInstant()
check((instant1 < instant2) == (instant1.toEpochMilliseconds() < instant2.toEpochMilliseconds()))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like a definition of this operation, whereas it is more nuanced. Better to use constant instants obtained from parse

core/common/test/samples/InstantSamples.kt Outdated Show resolved Hide resolved
@dkhalanskyjb dkhalanskyjb requested a review from ilya-g May 3, 2024 15:15
core/common/test/samples/LocalDateSamples.kt Outdated Show resolved Hide resolved
@Test
fun plusDuration() {
// Finding a moment that's later than the starting point by the given amount of real time
val instant = Instant.fromEpochMilliseconds(epochMilliseconds = 7 * 60 * 60 * 1000)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fear that overreliance on from/toEpochMilliseconds in samples would convey the wrong idea that Instant is completely defined by that number of milliseconds.

Copy link
Member

@ilya-g ilya-g left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!
Let's address what is clear and merge it, leaving debatable things for further improvement.

// Printing a given date-time format as a Kotlin code snippet that creates the same format
val customFormat = LocalDate.Format {
@OptIn(FormatStringsInDatetimeFormats::class)
byUnicodePattern("MM/dd uuuu")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be cool to show the substitution for yyyy which is more widespread instead.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@dkhalanskyjb dkhalanskyjb merged commit cff3fdd into master May 13, 2024
1 check passed
@dkhalanskyjb dkhalanskyjb deleted the doc-improvements branch May 13, 2024 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

API reference improvements
6 participants