Closed Egorand closed 6 years ago
I'm just a consumer of the API (private repo, would be affected by the breaking change but not in a way I couldn't recover from in 5 minutes), but it seems that the argument can be distilled into two things:
Let me ask a rhetorical question -- when driving, do you use a turn signal when you think nobody is looking? IMO, it's best to do the "right thing" even when nobody's looking.
@tbsandee, I just got some serious 13 Reasons Why vibe.
Still not convinced that renaming can be considered a behavior change though. I’m kind of in, but still consider this case an extreme over pragmatism at its best.
The worst thing I can imagine right now is related to an argument from Artem about Optional
being an exchange class between components.
Optional
.com.gojuno.koptional2
.com.gojuno.koptional2
.Should we provide an interop then? I need a drink.
I sure hope it's a good drink :D
We don't have to provide interop (although we can):
sed
command in the changelog that'll do the migrationSoooo?
Can I go ahead and:
?
Pros:
Cons:
I'd like to get this going.
@artem-zinnatullin, I’m in. Still sounds ridiculous for such a small library, but we made a mistake not taking Java into account and we are gonna pay the price of having 2
in the package name. Let’s do it.
Kool, implementing then 👍
@Egorand there is a compilation error (you can see it on CI):
e: /opt/project/koptional/src/main/kotlin/com/gojuno/koptional/Optional.kt: (1, 1): Duplicate JVM class name 'com/gojuno/koptional/Optional' generated from: package-fragment com.gojuno.koptional, Optional
e: /opt/project/koptional/src/main/kotlin/com/gojuno/koptional/Optional.kt: (5, 1): Duplicate JVM class name 'com/gojuno/koptional/Optional' generated from: package-fragment com.gojuno.koptional, Optional
That'd be nice!
@Egorand can you please update PR to make it compile and add few Java test cases?
Sure, will update the PR tomorrow
I think I've actually discovered a better solution that won't break existing clients and will improve Java experience: adding a companion object with an extra toOptional()
method. Kotlin clients should continue using the top-level extension function, Java clients would have to change from OptionalKt.toOptional()
to Optional.toOptional()
(the latter still works though). Also:
@JvmName
since we're ending up with two classes called Optional
- one for the sealed class Optional
and the other for the top-level function - that's a broken approach.toOptional()
version, but I see that there's no documentation at all in the file - should I add it?So, companion obj
+ @JvmStatic
pretty much hides this 2nd toOptional()
from Kotlin code, right.
What if we "hide" the first toOptional()
from Java? #yolo
If you add @JvmName("_toOptionalKotlin")
to the top-level toOptional()
function, this will remove it from autocomplete on Java side
That would be a breaking change, since Java clients who were using OptionalKt.toOptional()
will have to use the new method name. I like the idea in general, and it would be good to implement it for the next major release, for now I think it's fine to document correct usage for Kotlin and Java.
Yeah, we already agreed on 2.x release though.
Would be great to make initial approach with single toOptional
function declared properly for both Kotlin and Java work…
Technically it seems okay to have toOptional
declared as a static function in Optional
class, maybe we should submit a ticket to https://youtrack.jetbrains.com and describe our use case
Another solution is to write Koptional core in Java with proper Kotlin annotations and properly placed functions and see if Kotlin compiler works with that, I mean, that sounds like a fun experiment (not that I have time for it tho…)
The problem is that extension functions declared inside classes or objects can only be used as extensions inside those classes/objects, hence you'll need to always do Optional.toOptional()
, even in Kotlin. Rewriting the core in Java destroys the potential of making the library multi-platform. Opening a discussion on YouTrack sounds like a great idea, I'd love to get more insight on the issue.
Let’s go ahead without hacks and do a 2.x
as it was proposed in the first place. We screwed up with Java compatibility and it is OK to acknowledge it.
So, actually, what do we agree on?
As I mentioned, the change is not breaking, so it'd be fine as a minor update
@ming13, @artem-zinnatullin, are you OK to merge it as minor update?
ok, I double checked current version of PR, I think I'm good to merge this as non breaking change 👍
Kotlin:
toOptional()
extension most of the timeOptional.toOptional()
which is probably not that bad tbh (I didn't like that back then, but now I find it fine)Java:
OptionalKt.toOptional()
(I didn't like it back then, but now I find it ok, library was not intended to be used from Java so it's fine)Optional.toOptional()
which is very good@Egorand just couple things:
OptionalKt.toOptional()
? I mean it works, but a test would be great to make sure we don't break it in futureOptionalKt
one should not be used from Java and @JvmStatic
one is preferred?toOptional()
extension to avoid method call, some people are already upset about having to wrap their data with Optional, additional indirection might make their feelings worse, I don't think that's critical though, it should be easily inlined by JIT or AOTYeah no worries! I'll try to get the changes in today
@artem-zinnatullin 0dafabb
Sorry for delay, had miscommunication with Artur and was waiting for his review while he was waiting for me to merge heh
Sweet! Are you planning a release any time soon?
Yep, we can do a release with this PR only or wait for rest
@Egorand 1.4.0 was just released with this change, guys at Juno have some workload backpressure, I'm gonna take care of processes for some time
We're sometimes calling
toOptional()
from Java and it would be more convenient to haveOptional.toOptional()
instead ofOptionalKt.toOptional()
.