News for hackers. Stuff that matters.
Re:Kotlin 1.4 by The_rationalist on Tuesday August 18, 2020 @08:54AM (#24197998)
Replacing current courtoutine implementation to use Loom threads or inline classes to use Valhalla are both implementation details that should not at all change the user facing API and complexity.

Your second point somehow stand: exploiting such optimizations will either need a runtime check or to be enabled automatically based on your JVM target specified in your gradle/maven.

As for the long term, google devs are heavily contributing to Kotlinc and I hope they will pressure Android architects to replace dalvik with openjdk.

Re:Kotlin 1.4 by pron on Tuesday August 18, 2020 @09:43AM (#24198427)
> Replacing current courtoutine implementation to use Loom threads or inline classes to use Valhalla are both implementation details that should not at all change the user facing API and complexity.

This is not accurate.

Re Loom, the entire Java platform will be built around a "single colour" structure. Kotlin, like C#, is based on a split, two-colour, model. It is true that under the covers it could map both colours onto the same one, but that will mean that Kotlin adds a lot of unnecessary complexity, and possibly make it harder to target multiple platforms (i.e. a lot of Kotlin code that will work well on Java will not work well on Android or JS).

Re Valhalla, it will allow multi-component inline types -- that's a user-facing change -- but those won't work on Android, at least not without significant overhead.

Re:Kotlin 1.4 by jayd16 on Tuesday August 18, 2020 @12:03PM (#24200333)
Agreed, although I don't want to go so far as to say color is that intrinsic but they are different features with different goals.

Loom is about many blocking green threads that are scheduled without you thinking about it. Coroutines are meant to support UI programming where you deal with a marshaling the app flow to and from a main thread. Coroutines are more verbose but they handle different use cases than Loom.

That said, Kotlin coroutines are just a library anyway. Its a dependency change not a language change to swap out the implementation.

Re:Kotlin 1.4 by Nullabillity on Tuesday August 18, 2020 @09:59AM (#24198603)
> Re Loom, the entire Java platform will be built around a "single colour" structure. Kotlin, like C#, is based on a split, two-colour, model. It is true that under the covers it could map both colours onto the same one, but that will mean that Kotlin adds a lot of unnecessary complexity, and possibly make it harder to target multiple platforms (i.e. a lot of Kotlin code that will work well on Java will not work well on Android or JS).

Function colours are a useful modelling tool regardless of whether the underlying platform requires it. That's sort of like saying "everything is eventually just bytes anyway, so types are unnecessary complexity".

Of course, there are languages trying flatten everything into a single type. But personally, I'd rather not be programming PHP when there are better options available.

> Re Valhalla, it will allow multi-component inline types -- that's a user-facing change -- but those won't work on Android, at least not without significant overhead.

Not sure how that's any different from a library's perspective than "this API isn't available on older JVMs, so don't use it if you want to target Android".

Re:Kotlin 1.4 by pron on Tuesday August 18, 2020 @11:13AM (#24199637)
> Function colours are a useful modelling tool regardless of whether the underlying platform requires it.

Without getting into the debate over what valuable information the "async" colour communicates on a platform where, unlike in JS, global state changes could occur at any time due to thread concurrency, any thread can be suspended by either the VM or the OS at any point for any duration, and "async" is no cheaper than "sync", the more practical problem is that Kotlin does not know what colour the platform's operations are. This means that some arbitrary mixing of colours would work on one platform but might not on another.

I know some two-colour frameworks use BlockHound, a dynamic "colour detection" tool, but even as a dynamic tool and even today BlockHound sometimes gives wrong results because it doesn't keep up with the frequent changes to the platform.

> Not sure how that's any different from a library's perspective than "this API isn't available on older JVMs, so don't use it if you want to target Android".

Because it's not about libraries or versions you can upgrade but core language capabilities that differ by platform. It could be acceptable, but it means that there are different Kotlins for different targets.

We get a language whose both syntax and/or behaviour differs by platform, and isn't a first-class citizen on any but one of them.

Re:Kotlin 1.4 by joshlemer on Tuesday August 18, 2020 @11:14AM (#24199641)
I've never heard of this "single-colour" / "two-colour" distinction, do you have a link with more information? Thanks!
Re:Kotlin 1.4 by ragnese on Tuesday August 18, 2020 @12:47PM (#24200954)
http://journal.stuffwithstuff.com/2015/02/01/what-color-is-y...

Async/suspend functions are one color, and "normal" functions are another.

Re:Kotlin 1.4 by reducesuffering on Tuesday August 18, 2020 @01:40PM (#24201676)
Further, from reading TFA, one colour would mean only "normal" functions, correct?
Re:Kotlin 1.4 by ragnese on Tuesday August 18, 2020 @02:06PM (#24202040)
That's my understanding, yes.
Re:Kotlin 1.4 by kllrnohj on Tuesday August 18, 2020 @11:01AM (#24199462)
> I hope they will pressure Android architects to replace dalvik with openjdk.

Android hasn't used dalvik for ~5 years now. Switching from ART to OpenJDK runtime is both non-trivial in complexity (can't break existing apps), and doesn't bring any obvious benefits, either. OpenJDK isn't tuned nor optimized for the constraints that Android operates in, and ART isn't exactly a slouch, either.

The only benefit it brings in theory is just updated bytecode support, yet Android is still going to be stuck with dex, and still has the backwards & forwards compatibility issues, and OpenJDK doesn't help that situation at all. Nor have there been any significant bytecode changes/improvements in Java anyway, so you still don't get any benefits from it.

Re:Kotlin 1.4 by pron on Tuesday August 18, 2020 @11:21AM (#24199740)
> Nor have there been any significant bytecode changes/improvements in Java anyway, so you still don't get any benefits from it.

Java's core capabilities aren't just expressed as bytecodes -- there are lots of intrinsics, too, which, in this case, mean "native" capabilities exposed as library APIs but implemented in the VM and cannot be implemented in bytecode. Neither Panama nor Loom add or change any bytecode instructions, yet they drastically change the platform's core capabilities. Same goes for the module system -- it changes the accessibility/visibility rules in the VM but does add or change bytecode.

Re:Kotlin 1.4 by kllrnohj on Tuesday August 18, 2020 @12:40PM (#24200868)
And not all of those enhancements are unique to OpenJDK. ART can already emit direct FFI calls from Java, for example ( https://android.googlesource.com/platform/art/+/86c8752f6462... )

ART has also long had hooks for native allocations to influence GC pressure ( https://android.googlesource.com/platform/art/+/987ccff ) , which have improved to become automatic via malloc hooks & use phantom references for cleanup ( https://www.youtube.com/watch?v=7_caITSjk1k )

Similarly Loom isn't necessarily useful for client-side apps, as coroutines already fit that role and full green threads isn't useful. Most likely Loom would be a regression for mobile apps, as keeping key threads responsive is more important than maximizing throughput. And it definitely isn't going to be as tuned for things like big.LITTLE out of the gate as the existing Linux scheduler is.

The only ~significant area of issue here is those trying to build commonly portable Java libraries. But there's not much in common in practice here, and that shouldn't be the singular deciding factor.

But the meta-point here is how much of the "use openjdk instead!" crowd is simply overly familiar or buying in to OpenJDK hype & general JEP awareness, and simply isn't following along with what's going on with ART on the other side of things? ART isn't a bad runtime, after all, it's actually quite good. And it's had a lot of useful things that OpenJDK doesn't or only just recently got (like specifying what was null when an NPE is thrown - ART's been doing that for years)

Re:Kotlin 1.4 by thu2111 on Tuesday August 18, 2020 @03:23PM (#24203133)
ART can indeed ignore Loom, or better just map the virtual thread API to regular threads. It'd not work well for things like generators but those aren't a target of Loom at the moment anyway.

The lack of other features in ART does hold things back though. The list of bytecode and API features that ART doesn't have keeps growing and some would be useful on mobile. Panama will add a better FFI and a SIMD API, when will Android get that? Never? That would be a pity. What about Truffle/Polyglot? What about some of the neat tricks allowed by proper invokedynamic?

Other than licensing I do wonder why Google can't just bring the nice bits of ART across to HotSpot. It would save library developers a lot of heartache.

Re:Kotlin 1.4 by pron on Tuesday August 18, 2020 @01:29PM (#24201534)
Sure, but my point was about similarity/compatibility. It might be the case that Android has suitable alternatives to Java's features, and it's possible that they're even more suitable for Android's needs, but the point is that while the two platforms were quite similar ten years ago, and a single language could target both with few if any tradeoffs, this is increasingly becoming tenuous as the two platforms become dissimilar in fundamental aspects. A language that attempts that will increasingly find itself needing to make tradeoffs that it didn't need to, say, five years ago, or even today.
Re:Kotlin 1.4 by alex7o on Tuesday August 18, 2020 @09:04AM (#24198079)
As good as this sound this is a no go because of oracle/Google lawsuit. So they probably want to move away from java entirely.
Re:Kotlin 1.4 by pjmlp on Tuesday August 18, 2020 @10:37AM (#24199071)
Which will never happen unless they rebuild all their Java tooling with Kotlin/Native.

Or switch to something else like ChromeOS or Fuchsia, both with zero dependencies on anything Java related, including Kotlin.