150 points · by ingve · 9y ago · 85 comments
Along with swift, they should be the general purpose programming languages in the near future.
The problem is not the compatibility with the new Java API, but with the new bytecode definition. But it is going to have the same problems Java have. The big difference with Java here is that you can adopt new bytecode specifications without using the new Java APIs, or doing some modification in the bytecode generation to "simulate" those new features. And this is the key why it is taking over Android community. You can support legacy bytecode with new features. Which you cannot do with Java.
A problem for kotlin (and java) is the new packaging system. But kotlin is already working on it changing how they package their standard library. So it is even less problem than java.
There definitely is a problem, as can be seen e.g. here: https://discuss.kotlinlang.org/t/jdk-8-compatibility-of-kotl...
Quoting: "Sometime ago we introduced kotlin.Stream<T> type, with the simples possible interface – iterator() function – with the idea that we can make it compatible with Java8 Stream<T> type. Currently we seem to come to a conclusion it was a mistake as we cannot fine a way to represent Stream<T> as kotlin type in Java 6 & 7, and then use to Java8's Stream<T> when targeting JDK8. If you have any idea about how to make it work – please share!"
Basically, while Kotlin is more or less a straightforward extension of the Java 6'th Collections APIs, by Java 8's release the two have diverged. When programming in Kotlin, you would normally use its own functional APIs, not Java Streams API. While technically nothing prevents you from using Streams, they don't fully integrate with Kotlin's native Collections, so you're forced to choose one or another.
This makes no sense.
Kotlin has no collections, it just uses Java's.
Being part of the largest, most successful, best tooled ecosystem in software is an Achilles' heel? Most people would (and should) gladly take that over any particular language feature.
Could you give some example oF unique features of the toolsuite around the jvm ?
Every time I write java I think: I would had spent less time writing this in kotlin and the code would be more readable.
Every time I use a non-statically typed language and have a bug because of it I drop a tear thinking that I would never had that bug that took me a couple of days to find in kotlin.
Unfortunately that is not going to happen for Kotlin, unless it gets adopted by major projects, and by major I mean on the scale of Android.
Java is not going anywhere soon. If anything, Kotlin will become a second Scala.
Why do you think it will be behind scala?
Are there any benefits or tradeoffs, based on what you might know about Groovy?
What I think it is slower right now are the tools. Sometimes IdeaJ stucks. I guess they will be improving the performance slowly as right now they are other things in the language more important to focus.
It doesn't offer a compelling advantage. "Slightly cleaned-up Java with a bit of syntax sugar" is not enough to justify having to make all your tooling (IDEs, profilers, monitoring, code coverage ...) support a new language. And if you are going to make all that effort, why would you not pick a language that offers some genuine killer features in return, like Scala or Ceylon? And it's got a lot of special cases, a lot of stuff in the language that should just be libraries, that I think will make it hard to maintain in the long run (the "CoffeeScript of Java" line is probably fair). If anything it seems overhyped to me.
This is not an accurate description of Kotlin.
Kotlin has many features that make it better than Java. Most importantly, it is null-safe. In addition to that it makes it simple to enforce data-immutability, which is very difficult in Java.
https://kotlinlang.org/docs/reference/comparison-to-java.htm...
Kotlin does have nullability handling yes, but it's a very limited special-case feature - it's a language-level builtin rather than something you can use in your own libraries. E.g. if you want to have an error message in the failure case rather than just null (i.e. some kind of Result type), you can't reuse any of the null-safety functionality (whereas in Scala or Ceylon you can write the same methods to work with either optional/nullable or result-like types).
Data immutability isn't at all difficult in Java. It's tedious (sprinkling "final" everywhere), but not hard.
And C is a "slightly cleaned-up assemble with a bit of syntax sugar". I think kotlin has a lot of features that Java (even Scala an Ceylon) doesn't have, moreover it forces you to use good patterns when programming (it got a lot of ideas of effective java book).
I am curious why do you say Scala and Ceylon have killer features, what are those features that Kotlin doesn't have?
Personally I have used Scala and I prefer kotlin over it, even Java over Scala.
Going from machine-specific assembly to crossplatform C was a huge killer feature at the time.
> I am curious why do you say Scala and Ceylon have killer features, what are those features that Kotlin doesn't have?
Higher-kinded types and/or union types. Those are the real game-changers, even if they don't look like it in simple examples. More concretely, the real value proposition for moving from Java to Scala or Ceylon is "replace all your magic annotation/XML-based proxying/bytecode manipulation with ordinary library functions that follow the ordinary rules of the language".
Ceylon because it's a ghost town language that no one uses and that only programming language enthusiasts have even heard of. That's a catch 22 but it's the truth.
Scala because it's too different from Java for many Java programmers to be able to jump in and be immediately productive. It solves problems a lot of Java programmers don't even know they have.
The fact that Kotlin isn't that much different from Java is its compelling advantage. And the places it is different, like non-null types, solve problems that almost every Java programmer is going to understand and relate to.
I know :(. It's just very frustrating to have seen Ceylon and Kotlin come out at roughly the same time with roughly the same goals, one better designed than the other, and then watched the other one win.
> Scala because it's too different from Java for many Java programmers to be able to jump in and be immediately productive.
Idiomatic Scala that makes extensive use of native-to-Scala libraries has this property; Scala written in a Java-like style doesn't. I think it's too early to say that Kotlin won't experience the same thing as an idiomatic Kotlin style and native-to-Kotlin libraries emerge.
> It solves problems a lot of Java programmers don't even know they have. The fact that Kotlin isn't that much different from Java is its compelling advantage. And the places it is different, like non-null types, solve problems that almost every Java programmer is going to understand and relate to.
I think you would have to have a very finely calibrated level of attention to notice null was causing you problems and not notice that exceptions, AOP magic and the like were also causing you problems. I mean I'm sure many Java programmers regard bizarre transactionality bugs ( http://thecodelesscode.com/case/211 is a good example ) as an unfortunate fact of life rather than something to be fixed by better languages - but I expect those same people would also regard null pointer exceptions as an unfortunate fact of life.
I'm a lead Android developer and I've inherited a Kotlin codebase mixed with Java, and here's why I refuse to create any new classes in Kotlin:
1). Compile-time is slow. I know there are plenty of work-arounds but I don't want to modify the build-properties to the point where it's hard to replicate when onboarding new engineers. The closer to the default-project settings, the better and the less resistance. Android dev itself is a very fragile framework to begin with.
2). Abuse with nullable types. I've been a lead iOS engineer too and this is what I have observed as well with Swift. I can't even count the amount of Crashlytic reports that have been caused by a model not binding properly.
3). It really doesn't save that much time at the end of the day. A language is a language is a language.
4). Community/docs does not have as much reach as Java in terms of docs.
This speaks more to the previous developer than the language itself, but this has been the most unstable code-base I've ever worked with.
I specifically avoid web-development for the bandwagoning hype when the shiniest new piece of tech comes out. While I think it's great that Jetbrains is trying to make a competitive language to Java, I think there are too many forces working against them.
Java's old, boring and predictable, but that makes it a great language to a build a stable app with.
What kind of abuse? Too much or too little nullability?
I mean, in Java anything can be null unless it's a primitive type, so that should give you even more problems. Unless it's some sort of mapping of nullable values to non-nullable types that's giving you these crashes?
That's a... surprisingly uninformed statement from a "lead" developer.
My job as a lead is to help scale my team, properly architect the application as well as reducing any risk / uncertainty while delivering new features to the platform.
The syntax doesn't save that much time in my personal experience. The actual amount of words that's typed might be less.. it can be cleaner than Java but if my team is spending a higher amount of time debugging Kotlin issues relative to working with the Java codebase then we've got a problem.
---
> That's a... surprisingly uninformed statement from a "lead" developer.
That's a... surprisingly snarky / unhelpful remark with no counter to my statement.
Peek is to get the reference of the first element. OnEach makes a lazy operation for every element on the sequence. I would say that onEach is more like map but lazy.