Conversation
| private val initData: List<ByteArray> = listOf( | ||
| byteArrayOf(1, 2, 3), | ||
| byteArrayOf(4, 5, 6) | ||
| ) |
There was a problem hiding this comment.
Notice no guava dependency anymore, since collections in Kotlin are immutable by default, unless explicitly stated otherwise (in this case it would mean writing mutableListOf).
There was a problem hiding this comment.
Also, interesting to notice the type-inference for byteArrayOf when passing the list of values, another benefit of using Kotlin over Java.
| parcel.setDataPosition(0) | ||
| val formatFromParcel = Format.CREATOR.createFromParcel(parcel) | ||
| Truth.assertThat(formatFromParcel).isEqualTo(formatToParcel) | ||
| parcel.recycle() |
There was a problem hiding this comment.
In this final block, we could also apply some standard library functions to make the code a bit more concise.
|
In my opinion, there isn't a strong argument for us to start using Kotlin in the core library at this point in time. We (the whole team) spent some time using Kotlin toward the end of last year, and I agree there's a lot to like. However, forcing app developers who aren't already bundling the Kotlin runtime to do so is very painful. I would argue that it's probably significantly worse for us to do this than for a network stack library, because there are fewer good alternatives (that a developer could switch to) and because streaming media is an area that's evolving very rapidly (which makes it less viable for a developer to freeze on the current version for an extended period of time).
It's interesting that OkHttp have migrated. That will provide us with a data point to keep an eye on. It should be noted that not all of the feedback has been positive (e.g. some of the responses in square/okhttp#4723).
We're already using Checker framework to achieve this with the current Java implementation. The vast majority of the library is already checked, and we hope to complete removal of the remaining exemptions relatively soon. |
|
@ojw28 Thanks for sharing your opinion and the prompt response, as always. I'm curious on a few points you raised:
I think the work that has happened including nullability annotations greatly helps Kotlin consumers, but as I listed in the original message, there are more language-features that could make ExoPlayer an even better tool for developers on Android. |
|
I'd like to add that the proposal in this PR is to include Kotlin in test-sources only for now, which also means it isn't code that will be delivered to the final production APKs of app developers. It will be a good playground for the maintainer team to get familiar with the extra tools for modeling and API-design; besides making the codebase friendlier for newcomers overall. I have a good example of diff that would have been way less painful to produce given some features that Java unfortunately does not yet provide, like default parameters, value objects and copy constructors. |
|
For the general discussion. Maybe one way to approach this is to provide additional artifacts that are based on Kotlin to provide nicer API there? Usage stats then could show how many developers use which API to know when Exoplayer can fully switch. Kotlin is already the "preferred way" of writing Android apps for Google, so Java becomes the fallback solution. |
I'm not able to share that information here, sorry. Although I'd suggest that results from a survey of developers who use Kotlin as one of their primary programming languages is probably not the most reliable of indicators for measuring Kotlin adoption. We will continue to look at the language mix being used by app developers who also depend on ExoPlayer, and this will continue to be an input into deciding when it makes sense for us to start using Kotlin within the library.
Kotlin demo apps are great. We might convert some of ours as well. We're committed to making ExoPlayer easy to use from Kotlin (hence all of the nullness annotation work we've undertaken). It's unclear how this is directly related to what language we develop the core library in, however.
Yes, that's the main pain point. And yes, it's correct that those using OkHttp 4 will already be pulling it in. That's why OkHttp 4 adoption is a good data point for us to keep an eye on. Regarding the ExoPlayer OkHttp extension specifically, I can say that adoption is tiny relative to adoption of the core library.
There's no technical reason not to use Kotlin for tests, but I don't agree that it's beneficial to do so. It effectively requires developers to understand two languages before they can do anything, rather than one. I think there needs to be a bigger payoff than being able to use Kotlin syntax in test code for that to be worthwhile.
This argument gets floated a lot for tooling that might make the development team's job a bit easier. You can make a similar argument for insert your favourite dependency injection framework here, AutoValue, other annotation processors and so on. If you're developing an app then this argument often makes sense, but the same is not so true when you're developing a widely used open source library that a large number of developers from different companies need to dip in and out of. The more tools we use, the harder it is for developers to do this. Some development inefficiency on our side is a price worth paying for keeping the code accessible to the widest group of external developers. This doesn't mean that we we'll never adopt additional tooling, but it does mean that the bar for adoption is significantly higher than it would be were we developing an app.
The
We've considered doing this, and I agree that it seems like a much better approach. We didn't see any compelling reasons or use cases to prioritize a more in depth investigation, however. |
|
If you changed APIs to Kotlin, callers would benefit from named & default parameters. That’s amazing! |
Kotlin is becoming an industry-standard for Android development. It is also endorsed by Google as a 1st-class language for writing apps; and even some official documentation and ExoPlayer sample apps are already written in that language.
Many companies from various sizes have already adopted Kotlin and some important libraries on the Android ecosystem start to migrate to Kotlin as well.
This PR is a request-for-comments, mostly from the ExoPlayer core development team, but also open for the general community.
Besides making ExoPlayer's API type-safe with regards to nullability (while still providing Java interop), replacing
@IntDefs withsealed/inlineclasses for better discoverability and many Guava usages in favor of the standard library ones, using Kotlin would also allow us to greatly reduce the API surface: drop a big number of method overloads (that could be replaced for default parameters and copy constructors), all parameter annotations in favour of language-supported named parameters (again with type-checking), etc.I'm sure there are other benefits that I'm immediately missing to list.
For now, it only introduces the dependency to the Kotlin runtime on the
library-coremodule and only for thetestbuild type (hopefully we agree on making Kotlin available to even more modules and later to production code).This PR converts a single test case (
FormatTest), simple enough to see how a usage of the stdlib removes a Guava dependency (plus the mental overhead of dealing with mutable collections). There would be way greater benefits in converting more interesting test suites, likeExoPlayerTest, for example.At SoundCloud (and the approach I would propose) our experience was to introduce new code in Kotlin, and only convert Java to Kotlin as we needed to touch it. I'm happy to provide more in-depth details of our experience if that's of interest of the Exo team.