[HN Gopher] Kotlin Coroutines runtime in 400 lines
___________________________________________________________________
Kotlin Coroutines runtime in 400 lines
Author : dokar
Score : 27 points
Date : 2023-11-16 12:32 UTC (10 hours ago)
(HTM) web link (github.com)
(TXT) w3m dump (github.com)
| peterisdirsa wrote:
| I don't get it. How is this different than using standard Java
| ExecutorService & co features?
| Shawnecy wrote:
| I'm curious as well. Once you can use an ExecutorService with
| virtual threads, the gap seems a bit thin.
|
| The best I can tell is that coroutines are a bit lighter weight
| (in terms of what state is managed) and have a bit simpler
| usage out-of-the-box.
|
| But I've not used them myself so maybe I'm not seeing how big
| of advantage those are or perhaps there's more to it than that?
| jayd16 wrote:
| Well for one, virtual threads would be implicit blocking and
| this style is explicit.
| _ZeD_ wrote:
| so kotlin functions are colored while java ones are
| colorless?
| mst wrote:
| It explicitly says it's not for actual use.
|
| The point (I think) was as an exercise to demonstrate it was
| possible to implement in 'userland' and how they did so.
| tadfisher wrote:
| The runtime uses ExecutorService and friends to run coroutines,
| which are bits of CPS-transformed Kotlin code that are
| generated when you compile a 'suspend fun' declaration.
| lfmunoz4 wrote:
| The way the code looks is completely different and
| significantly cleaner and faster to write in Kotlin. Actual
| performance and final functionality is likely to be same.
| kubota wrote:
| Kotlin had its time in the sun but it's a harder swallow now with
| Java's release cadence closing the gap every 6 months.
| somehnguy wrote:
| Not sure I agree with that. We've been using Kotlin on all new
| projects for the last year or so and I strongly prefer it over
| Java at this point. It has many language conveniences that make
| the code more succinct. Suspend functions also make it
| extremely simple to parallelize certain things without any
| ceremony.
| DarkNova6 wrote:
| Which tech domain are you working in?
| htamas wrote:
| I agree. I've almost exclusively been working with Kotlin
| (and a little Go) for the past 5 years, writing backend code.
| Recently our team got the responsibility to take over an
| other project where the repos are written in Java. The
| difference is clear, it's like coding with one of my arms
| tied to my back.
| Clamchop wrote:
| This take keeps coming up and I do not get it. Kotlin has
| ergonomics that Java cannot match without breaking changes that
| are anathema to the JCP, and Java has no answer at all for
| multiplatform.
|
| I have lots of respect for Java but I still greatly prefer
| Kotlin.
___________________________________________________________________
(page generated 2023-11-16 23:02 UTC)