News for hackers. Stuff that matters.
Re:From zero to 10M lines of Kotlin by ohgodplsno on Tuesday October 25, 2022 @09:02AM (#33329899)
Kotlin is plenty safe for now.

* Android is a massive platform, and Android is basically stuck on JDK8 (or JDK11 with desugaring, wooo).

* iOS compatibility-ish. KMM is not ideal and mostly generates ObjC compatible objects (so generics are mostly screwed for Swift and writing iOS code is not ideal, but even being able to define common and enforced contracts is cool. iOS benefiting from projects like SQLDelight is super cool)

* Jetbrains hedged their bets, and Kotlin/Multiplatform is a solid option. Coupled with Jetbrains Compose for UIs as well as having the entire Java ecosystem available is very solid. Compilation for so many platforms, directly to native executables is cool.

* Java is still very slow to evolve. Kotlin has had data classes for a long time, Java recently added records. Inline classes offer some nice type safety at basically zero costs. Coroutines and structured concurrency are a beautiful way to work, and Project Loom would only build the foundations of that. Context extensions (while terrifying in the potential for spaghetti code they offer) are a useful feature, reified generics have some great potential.

Now, Kotlin has its disadvantages too. Compilation times are not that great (hopefully K2 fixes this partly), but it's relatively safe and is kind of more than just a JVM language by now.)

Re:From zero to 10M lines of Kotlin by kaba0 on Tuesday October 25, 2022 @09:32AM (#33330237)
> iOS compatibility-ish

I don’t know how well it works, but we have seen these kinds of projects, and they seldom work as is. Not sure how well Scala Native works, even though it predates Kotlin’s try. (Though scala.js is surprisingly good!)

But do you really think that a relatively young language like Kotlin with minuscule adoption (compared to java) will be better at this game then Java?

Java has a very good compiler to Js maintained and used heavily by Google (j2cl, part of their closure compiler toolkit), which can also output obj-c code. These are/were used heavily for porting their shared libs between basically all platforms.

For native, Graal is a very cool way forward benefiting all JVM languages (as well as scripting languages, its polyglot features are insane).

> Java is still very slow to evolve

Is it a problem? The majority of developers don’t like running after the language, even though it may seem so based on online hype circles.

Re:From zero to 10M lines of Kotlin by ohgodplsno on Tuesday October 25, 2022 @10:03AM (#33330594)
>I don’t know how well it works,

Well enough, provided you stay within the known bounds. Hell, some people at Touchlab even went as far as porting Jetpack Compose to work on iOS (which, uh, I would not recommend in its current state), and it technically works. I probably wouldn't recommend writing all of your app logic in Kotlin, but being able to share the data layer is amazing.

>But do you really think that a relatively young language like Kotlin with minuscule adoption (compared to java) will be better at this game then Java?

It depends on where you're looking. Most modern android development will most likely be done in Kotlin. Backend work, for things started relatively recently, Kotlin is not surprising. But mostly, Java does not make iOS compatibility a goal. Java tell you "get a JVM and run our shit" (or get GraalVM and have basically an embedded JVM). Kotlin has two sides, and Kotlin/Native does not depend on the JVM.

>Java has a very good compiler to Js maintained and used heavily by Google (j2cl, part of their closure compiler toolkit), which can also output obj-c code. These are/were used heavily for porting their shared libs between basically all platforms.

j2cl still brings in a light JVM to the Web. Kotlin does not. It provides interop to the JS APIs as well as its own tech, but it's not meant to take your Kotlin code and immediately run it on the web (which is an awful, awful idea). You're still meant to write your browser specific code, your android specific code, your x86 specific code, etc. In any language you want, even! Write it in Kotlin/JS, or let your typescript consume the Kotlin/JS bindings. However, you can have a common base that'll work everywhere.

> For native, Graal is a very cool way forward benefiting all JVM languages (as well as scripting languages, its polyglot features are insane).

Graal is an extremely cool project, but with different goals. Write once, run everywhere is a lofty goal, but it only works on very similar platforms (Windows/Linux/OSX). Kotlin has taken a Write once, specialize what is needed approach.

Re:From zero to 10M lines of Kotlin by kaba0 on Tuesday October 25, 2022 @12:47PM (#33333075)
> even went as far as porting Jetpack Compose to work on iOS

Well, Gluon promises the same for JavaFX apps and there is a sample app actually downloadable from the AppStore.

> j2cl still brings in a light JVM to the Web

Not at all, it compiles to very optimized Javascript. Oh, and I forgot to mention that there is also teavm, which is not a VM contrary to its name -- this latter transforms java byte code so it works with guest languages as well.

Re:From zero to 10M lines of Kotlin by andrekandre on Tuesday October 25, 2022 @06:18PM (#33336887)

  > but being able to share the data layer is amazing.
why not just use swagger/openapi + auto generated models?

adding kotlin native adds huge depenencies relative to the tiny benefit of a datamodel that can be auto generated to native code imo

Re:From zero to 10M lines of Kotlin by ohgodplsno on Wednesday October 26, 2022 @05:08AM (#33341337)
Swagger + OpenAPI generates data classes for you, and maybe a Retrofit/Ktor/Whatever interface. It does not handle repositories, data fetching, caching and combining, it does not handle a SQLite database.

Which dependencies ? If you already have Android devs, on the iOS side it adds a single swift package, and similarly so on Android.

Re:From zero to 10M lines of Kotlin by andrekandre on Wednesday October 26, 2022 @11:37AM (#33345348)

  > It does not handle repositories, data fetching, caching and combining, it does not handle a SQLite database.
right, but you can use that to autogenerate all those things (have done it before in very large e-commerce app for several platforms/apps) with a few additional tools and have it all automated (especially useful when api definitions change because now you dont need to manually update everything by hand)

  > Which dependencies ? If you already have Android devs, on the iOS side it adds a single swift package, and similarly so on Android.
for ios, its including basically the whole kotlin runtime and additional support (kotlinx-datetime, etc) in that single package (xcframework), then add a lot of data classes and things start to add up... for us its the biggest single dependency by far
Re:From zero to 10M lines of Kotlin by mbStavola on Tuesday October 25, 2022 @09:31AM (#33330225)
I agree with everything you said except for "Java is still very slow to evolve."

New Java versions are cut every six months since 2017 and since then has added a significant amount of new features, syntactical sugar, APIs, et cetera. Not only that, but they've also have been pretty aggressive IMO in deprecating and removing legacy. Very very different than the Java I remember working in years ago.

Re:From zero to 10M lines of Kotlin by weego on Tuesday October 25, 2022 @09:49AM (#33330422)
You're correct of course, but to back up the parents comment, they do have a habit of implementing things other than the low hanging fruit that developers are frustrated not having, leading the drive towards other jvm langs
Re:From zero to 10M lines of Kotlin by mbStavola on Tuesday October 25, 2022 @11:48AM (#33332185)
What are some examples of those low hanging fruits?
Re:From zero to 10M lines of Kotlin by ohgodplsno on Tuesday October 25, 2022 @12:40PM (#33332968)
Functional/SAM interfaces (transforming interfaces with a single method into a simple lambda), pleasant usage of lambdas (last lambda parameter can be put outside of the call like(this) { ... }, leading to a language that lends itself really well to building a DSL, coroutines were not a low hanging fruit but absolutely are infinitely more pleasant to use than RxJava, operator overload including invoke(), ranges that are pleasant to use (0 .. 10).forEach { }, or when (floatVariable) { in 0.0f .. 1.0f -> ... }, pattern-ish matching with when (not quite full on functional language powerful, and I believe that Java is not only catching up to it but making their switch quite a bit better), a standard lib that is packed full of extremely useful and consistently named methods, extension functions, delegation (if you inherited a SDK that has a piss poor interface, you can simply make a SDKWrapper(val internalSdk: SDK): SDK by internalSdk, which means that it will automatically implement it, and you can then have your wrapper do whatever around it (logging, better functions, DI, etc.)))

Kotlin is truly a pleasant language, both when you don't know it (although it can look a bit symbol soup-y at times for juniors), and when you fully know it.

Re:From zero to 10M lines of Kotlin by origin_path on Tuesday October 25, 2022 @01:13PM (#33333396)
Just browse through the Kotlin standard library. It's basically just a set of mappings to the Java standard library with a whole lot of extension functions to make it easier to use.
Re:From zero to 10M lines of Kotlin by quantified on Tuesday October 25, 2022 @10:30AM (#33330944)
In HN a while back, an Oracle dev pointed out that the evolution is slow for a reason. Which confirmed slow. New releases every 6 months, but not that much in the way of changes. This isn't criticism of the fact of it or going into why it is or whether it should be that way. It's just a statement of fact.
Re:From zero to 10M lines of Kotlin by Alupis on Tuesday October 25, 2022 @10:54AM (#33331306)
> New Java versions are cut every six months since 2017 and since then has added a significant amount of new features

And yet, the overwhelming majority of the Java community are still using JRE8 with none of these new features.

There are some that love this new pace of language development, but very few are actually using new features in production code.

Re:From zero to 10M lines of Kotlin by yardstick on Tuesday October 25, 2022 @11:20AM (#33331794)
The hesitancy in jumping beyond JRE8 is the large backwards compatibility road bumps in JDK9-11, and now again with 17/JavaEE->Jakarta. I wish Java would continue to add new features but be a lot more considerate of avoiding, completely, migration headaches.

We are migrating Java 8 -> 17 now and it’s been a right royal pain. I’m glad we didn’t jump to 11 LTS, and instead make one big leap. It might be a very long time before we do another LTS upgrade if they keep making poor migration choices.

Re:From zero to 10M lines of Kotlin by kaba0 on Tuesday October 25, 2022 @03:31PM (#33335079)
The only relatively bumby migration was 8->9. After that it is a very smooth ride, and that bumpiness was the price for the accumulated tech debt/slow down from the end of the Sun era.
Re:From zero to 10M lines of Kotlin by Alupis on Tuesday October 25, 2022 @06:46PM (#33337202)
Well, my understanding is (but I have yet to personally experience) the migration from 17 -> 18+ is rough because of all the javax.* packages being renamed jakarta.*

Which likely means touching a pretty significant portion of your codebase for the upgrade, and then who knows what 3rd party libraries you depend on are expecting...

So it may be as simple as Find/Replace for some folks, for others, it might be a deep dark rabbit hole.

Not breaking things used to be Java's MO. Yes, that means a ton of legacy cruft built up over the years... but we used to be able to depend on Java to "Just Work".

Perhaps some of this is necessary. After all, the C# folks seem to have no problem breaking everything to add new features... but I'd assert the Java community as a whole is much less tolerant of breaking changes and rapid deployment of features.

Re:From zero to 10M lines of Kotlin by kaba0 on Wednesday October 26, 2022 @01:32AM (#33340168)
There are entire segments of the industry that has never touched any javax package - while no doubt widespread, I do believe that it is still a very fair price to pay, and none of these changes were even half as problematic as for example the python 2->3 migration. So I don’t know, I’m fairly sure it is impossible to keep a platform alive with even less/smaller impact breaking changes.
Re:From zero to 10M lines of Kotlin by vips7L on Wednesday October 26, 2022 @12:30PM (#33346071)
javax -> jakarta is entirely dependent on your dependencies not the vm.

There’s plenty of dependencies that provide javax implementations as well as jakarta.

Re:From zero to 10M lines of Kotlin by vips7L on Wednesday October 26, 2022 @12:25PM (#33346004)
8 -> 9 wasn’t that hard for me personally. For our applications it was just adding things to the build to make sure javax.xml was present.

The real difficulty for us was upgrading the Play framework since the Scala community likes to make breaking changes with every release.

Re:From zero to 10M lines of Kotlin by bitexploder on Tuesday October 25, 2022 @09:34AM (#33330253)
Do languages really need new features every N months to stay relevant?
Re:From zero to 10M lines of Kotlin by nordsieck on Tuesday October 25, 2022 @09:41AM (#33330336)
> Do languages really need new features every N months to stay relevant?

I think a fixed N month release schedule is much healthier than what Java did before, which was wait until everyone was on the bus in order to ship, which resulted in multi-year delays.

Re:From zero to 10M lines of Kotlin by ohgodplsno on Tuesday October 25, 2022 @09:52AM (#33330468)
Depends. Is stuff like context receivers (https://nomisrev.github.io/context-receivers/) needed ? No, although it's a fun experiment. Are multiple receivers needed (https://youtrack.jetbrains.com/issue/KT-10468/Multiple-recei...) ? Not really, but when you are dealing with the JVM, nested class hell is a very common thing, and cleaning up your code is always pleasant. Implicit namespacing ? (https://youtrack.jetbrains.com/issue/KT-11968/Research-and-p...) Fun thing to get.

The thing is, they're all optional. You're never going to use any of these features if you don't need them. Your code can stay as a nested list of calls. But put them all together, and you can have code that is super explicit about what it needs to do, without having to re-pass things that are already there.

Re:From zero to 10M lines of Kotlin by AnimalMuppet on Tuesday October 25, 2022 @02:27PM (#33334372)
Depends. Are the features making things better, or just more complicated?

Even if it makes things better only for, say, 10% of users, but doesn't make it worse for the other 90%... the users will take that every N months for as long as the language authors can do it.

Re:From zero to 10M lines of Kotlin by kaba0 on Tuesday October 25, 2022 @03:34PM (#33335109)
No, but fortunately Java doesn’t do that. They have long running projects, when one is nearing completion it will be put in preview in the upcoming release. No rush to make it into anything, it’s ready when it’s ready. (Which should be copied by the rest of the industry as well)
Re:From zero to 10M lines of Kotlin by biztos on Tuesday October 25, 2022 @09:50AM (#33330428)
I’m not a Kotlin user, but this struck me as ambitious:

> having the entire Java ecosystem available

and, in the same point:

> Compilation for so many platforms, directly to native executables

Does this mean you can compile pretty much any Java libraries to non-JVM executables?

Re:From zero to 10M lines of Kotlin by MrPowerGamerBR on Tuesday October 25, 2022 @09:55AM (#33330491)
No, if you are targeting a different platform you can't use JVM libraries.

If you your target is JavaScript, you can use JavaScript dependencies (sort of: they won't have any type bindings so you will need to code then yourself) but you can't use any JVM libraries on it.

Re:From zero to 10M lines of Kotlin by slively on Tuesday October 25, 2022 @09:55AM (#33330501)
No, if you use Kotlin native you do not get access to Java libs.
Re:From zero to 10M lines of Kotlin by ohgodplsno on Tuesday October 25, 2022 @10:05AM (#33330607)
As other said, yep, you do not get the Java ecosystem if your target is native executables (or JS). there are alternatives like kotlinx-datetime, kotlinx-serialization, the kotlin stdlib. However, if you know you're going to stay on a JVMable target, feel free to not use Kotlin/Multiplatform, but regular JVM Kotlin libraries
Re:From zero to 10M lines of Kotlin by yCombLinks on Tuesday October 25, 2022 @01:55PM (#33333997)
Slow to evolve and long-term backwards compatibility are selling points.