Alyona Chernyaeva
06/04/2024, 12:57 PMCLOVIS
06/04/2024, 1:50 PMAlyona Chernyaeva
06/05/2024, 1:51 PMCLOVIS
06/05/2024, 2:07 PMmbonnin
06/11/2024, 9:46 AMlouiscad
06/11/2024, 2:59 PMmbonnin
06/11/2024, 2:59 PMCLOVIS
06/11/2024, 3:35 PMmbonnin
06/11/2024, 3:53 PMauthors >= makers > creators
🙂
“makers” has some hardware vibes to me. It’s cool but “authors” might be a bit more mainstreamzsmb
06/11/2024, 3:59 PMlouiscad
06/11/2024, 4:14 PMCLOVIS
06/11/2024, 4:17 PMlouiscad
06/11/2024, 4:18 PMFleshgrinder
06/16/2024, 9:24 AMList
vs listOf
that I'm talking about. The companion operator invoke-pattern as well as having a top-level function with the same name as the type pattern are used by many and it reduces the mental burden on users. I feel that this is especially important for library authors who cannot count on the same massive user base as the standard library can.
I'm posting this to the channel as well so that the discussion on this can continue in a dedicated thread. Just in case someone wants to actually discuss any of what I wrote.mbonnin
06/16/2024, 9:32 AMmbonnin
06/16/2024, 9:36 AMFleshgrinder
06/16/2024, 9:45 AMmbonnin
06/16/2024, 9:50 AMFleshgrinder
06/16/2024, 9:55 AMmbonnin
06/16/2024, 9:59 AMCLOVIS
06/16/2024, 10:00 AMCLOVIS
06/16/2024, 10:00 AMmbonnin
06/16/2024, 10:00 AMCLOVIS
06/16/2024, 10:01 AMCLOVIS
06/16/2024, 10:01 AMCLOVIS
06/16/2024, 10:02 AMmbonnin
06/16/2024, 10:03 AMmbonnin
06/16/2024, 10:05 AMFleshgrinder
06/16/2024, 10:29 AMvalue class SomeValue(val value: String)
can be useful despite being anemic. The problem arises if users add all functionality externally without utilizing the fact that SomeValue
already represents what they need. For instance, it could enforce non-empty strings: value class SomeValue(val value: String) { init { require(value.isNotEmpty()) } }
. It could also have a method like length
that returns the codepoint count instead of the default LATIN-1/UTF-16 char count. Using an extension for this means others can overload length
with their interpretation, making it unclear what length
represents without checking the imports.mbonnin
06/16/2024, 10:46 AMvalue class NonEmptyString(val value: String) { init { require(value.isNotEmpty()) } }
I’m onboard with that, I read the guide as non-empty
is part of the “core” functionality of the class (so it’s fine for that logic to be in the constructor)
> have a method like length
I wouldn’t do this. Or if doing this, I would also make value
a private implementation detail, e.g. private val value: String
. Having length()
as an extension function and the underlying value public
kind of mixes the contract of that class. Does it represent an UTF-16 string? a sequence of codepoints? something else? Not sure. The good thing is that by making value
private then it forces length()
to be method again (and not an extension).
Now the problem is defining what is “core” vs “not-core”. And I’m not sure there’s an universal definition there...Fleshgrinder
06/16/2024, 10:58 AMprivate
you do what I advocate for. Proper encapsulation with meaningful behavior. 😊mbonnin
06/16/2024, 11:04 AMsimon.vergauwen
06/17/2024, 8:58 AMinline
on interface
• Need reified
on interface
• Multiple receivers, extension methods defined inside interfaces, or classes.
• Covariance. If but only if adding an additional type parameter isn't possible, or UnsafeVariance is not desired.
Namespaces, or module imports, could drastically help here with the import/discoverability issue which could eliminate that problem.
It's been a long time ago, but once I worked on a library with an excessive amount of extension functions, and it would obliterate IDEA. Granted, that was a long time ago before Kotlin 1.4 new inference if memory serves me right.CLOVIS
06/17/2024, 9:00 AMFleshgrinder
06/17/2024, 9:01 AMsimon.vergauwen
06/17/2024, 9:02 AMCLOVIS
06/17/2024, 9:06 AMsimon.vergauwen
06/17/2024, 9:07 AMmbonnin
06/17/2024, 9:09 AMdiscoverability issuesCompose
getValue
on by remember {}
comes to mind.
Anecdotally, I just copy/pasted a bunch of Ktor code and needed to Command + Enter all the imports (route
, get
, etc...) because they weren’t added automatically.mbonnin
06/17/2024, 9:10 AMsimon.vergauwen
06/17/2024, 9:10 AMzsmb
06/17/2024, 9:10 AMephemient
06/19/2024, 6:27 AMFleshgrinder
06/19/2024, 6:39 AMmbonnin
06/25/2024, 9:44 AMephemient
06/25/2024, 11:24 AM