eygraber
04/21/2021, 12:31 AMAnother change is a set of new factory functions for creatingI saw ☝️ in the release notes for 1.5 RC, and I'm curious what the reasoning is for deprecating the extension properties. I found it to be a very nice API. Was it about polluting the namespace?instances from integer values. They are defined directly in theDuration
type and replace the old extension properties of numeric types such asDuration
.Int.seconds
knthmn
04/21/2021, 12:55 AMjw
04/21/2021, 1:29 AMjw
04/21/2021, 1:30 AMnanodeath
04/21/2021, 3:31 AMilya.gorbunov
04/21/2021, 6:32 AMfun java.time.Duration.toKotlinDuration(): Duration =
this.seconds.seconds + this.nano.nanoseconds
It's quite strange that seconds
is a property of seconds
and nanoseconds
is a property of nano
numbers.Javier
04/21/2021, 7:30 AMilya.gorbunov
04/21/2021, 8:20 AMJavier
04/21/2021, 9:47 AMthis.seconds.seconds
is something that will happen under the hood more the time and in utilities or extensions, but the rest of the time it works perfectly and there is where we are going to be the 99% of the time.Javier
04/21/2021, 9:49 AMilya.gorbunov
04/21/2021, 11:01 AMsomeSeconds.seconds
happens not under the hood, but every time you read someSeconds
value from where it is stored as a number.
As soon as you go from constants to variables, these extension properties begin to look as an abuse rather than a clever hack.jw
04/21/2021, 12:54 PMeygraber
04/21/2021, 3:58 PMilya.gorbunov
05/05/2021, 6:59 PMDuration
together with a helper function for bringing this object into context, e.g.:
fun duration(Duration.ConstructionExtensions.() -> Duration): Duration
val interval = duration { 1.minutes + 5.seconds }
eygraber
05/05/2021, 7:17 PMeygraber
05/05/2021, 7:56 PMeygraber
05/05/2021, 9:18 PMeygraber
05/05/2021, 11:42 PMilya.gorbunov
05/06/2021, 6:45 PMYeah it seems like a long-term proposal for literal conversion notation would be a good path to pursue.@jw yeah, that also could be an interesting direction to explore. Any ideas how these custom literals could look like? I found one idea here: https://github.com/Kotlin/KEEP/pull/24#issuecomment-224888801, but it's not quite clear how to avoid conflicts with predefined literal suffixes.
jw
05/06/2021, 7:08 PMJoffrey
05/06/2021, 11:11 PMduration { ... }
context could be an idea, but honestly I'm not sure the gain from the limited scope is worth the extra boilerplate. I like the idea of a sigil for literals, but I wonder how practical and understandable that would be (I also feel like that would be an unnecessary addition to the language).jw
05/06/2021, 11:21 PM4::seconds
, "1234"::BigInteger
(that's a function call named like a type), Etc.
And then it's basically a soft keyword on a regular extension function like Andrey proposed but they otherwise do not appear as extensions on the type.jw
05/06/2021, 11:22 PM1234::BigInteger
work with overloadingjw
05/06/2021, 11:24 PMjw
05/06/2021, 11:24 PMJoffrey
05/06/2021, 11:35 PMrnett
05/06/2021, 11:42 PM[1]
vs a tensor of 1
) so it would be nice to support it in a similar way to whatever ends up being done there. It's somewhat different semantics than the "unit conversions", but usually done via a similar syntax.