264 points · by ingve · 11y ago · 223 comments
The only downside is that it seems to be immature and not very widely adopted yet, but at least it has a strong backer in Jetbrains.
I would like to hear what people with more experience in the Java world think of it versus other alternate JVM languages.
So while Scala doesn't have to fear Java's evolutions, Kotlin seems to be risking obsolescence when Java gets good enough - and it's already happening with Java 8. Just look at the article: they talk about Kotlin as a good language for people stuck with Java 6.
* Type-safe DSLs
* Named parameters with default values
* Non-nullable types
* Raw strings (which make working with regular expressions quite nice)
* Type inference
* Properties
* Smart casts
* the when keyword which is much better than using switch statements
* data classes (very nice when working with APIs which expect Java beans)
* a lot of stuff I probably forgot
That sounds very good. Scala overdid it.
You've basically summarized Kotlin's design goals. Java was designed to be a simple language for widespread use, hiding an extremely powerful runtime beneath it. The very first paragraph describing its design reads[1]:
Java is a blue collar language. It’s not PhD thesis material but a language for a job. Java feels very familiar to many different programmers because I had a very strong tendency to prefer things that had been used a lot over things that just sounded like a good idea.
So: 1/ not PhD thesis material, 2/ familiar, 3/ adopt tried-and-true solutions.
Scala's design is the exact opposite of each and every one of these goals, but Kotlin tries very much to follow them. As such, they are very different languages (even though they share many features) because they are guided by opposite philosophies, and are therefore meant for completely different audiences. Kotlin aims to be exactly what Java would have been if it had been designed today; Scala aims to be something completely different.
[1]: http://www.win.tue.nl/~evink/education/avp/pdf/feel-of-java....
The fact that Kotlin has fewer features than Scala is what makes it appealing to me.
Scala has become a kitchen sink with too many features, it's kind of the C++ of the 21st century in that respect.
This misunderstanding mostly happens because some people start learning Scala in the hope of finding a better Java. But Scala is not a Java++, but something else entirely, being the kind of language that makes sense outside the boundaries of the JVM.
As a piece of advice, if you aren't interested in trolling, you might want to name actual things that you don't like, as in things that you can talk about, instead of things that are non-falsifiable. That way, in case you have a point, then other people or even Scala's or Kotlin's language designers can learn from your feedback. And if you don't have a point, then you might get some useful piece of advice.
On Kotlin - I don't like that it doesn't diverge enough. This is because when picking a non-mainstream language, you lose the advantages of mainstream languages, like easily available documentation, copy/paste-able samples, big developers pool, etc, etc... so the advantages of the non-mainstream language would better be worth it to balance the disadvantages ;-)
The only issue is that the Android framework code is still written in java, so it might not be that useful for the parts of an app that are deeply embedded in the android framework.
I really hope that the google people take notice of Kotlin and decide to adopt it.
Judging from the public commits in AOSP, java 8 & 9 seems to be the current official focus, but there is no way to know what is going on under wraps.
Kotlin promises 100% interoperability with Java, and Android appears to be a particular area of focus (Android Studio is based on Jetbrain's product, and Jetbrains makes Kotlin).
I would still love to see Kotlin pushed as the platform's language or alternatively a Rust inspired language.
Another big challenge of such a move would be the back compatibility story.
Now that I know that, Kotlin looks pretty cool! It proposes solutions to a lot of the most painful problems in Java.
I'm not sure the solutions are always correct, though. When I hear "null safety", I think "pattern matching on a Maybe sum type to statically ensure non-nullness", but what the talk says Kotlin actually provides is pressuring you into writing a bunch of your code in the Maybe monad, thus spreading nullness far and wide. The talk example is "println(a?.length())".
Maybe that's the best pragmatic solution in Kotlin, or maybe the talk oversimplifies what Kotlin actually gives you, but it kind of seems like the wrong direction to go in to me (most of the time!)
Kotlin allows non-nullable reference types, so you can declare a method as taking a non-nullable reference to an object. Now within that method, you know that reference is never null, and don't need to check it. When you call it, you have to either check for null beforehand, or pass something that is already guaranteed not to be null.
It's kind of like it builds a wall between things that could be null, and things that can't be, instead of having theoretical potential nulls all over your code. When you think about it, it seems like a pretty natural thing for a strongly-typed language to do.
fun myFunc(a: Int?): {
if ( a == null ) {
// handle the null case
}
// a is guaranteed non-null here
}
EDIT: And, of course, you can just use non-nullable types: fun myFunc(a: Int) {
// a is guaranteed non-null
}Wanted to ask for a step-by-step guide for awfully lazy developers, but found one myself. I suppose I'll leave a link here: http://blog.jetbrains.com/kotlin/2013/08/working-with-kotlin... (haven't tried that yet, though)
The fact that it hasn't "happened yet" is a bit worrisome though. To the point that I honestly think the answer at this point is Java. It will never be awesome but it will get a bit better every year.
https://docs.google.com/document/d/1ReS3ep-hjxWA8kZi0YqDbEhC...
The fact that they still (afaik) recommend sbt as a build tool is telling.
[1] http://stackoverflow.com/research/developer-survey-2015#tech...
A lot of people overlook ceylon because the language is just not promoted too well currently: even though the documentation is comprehensive, it's not focused on the features the programmers are interested about. And they need more target platforms, but they are already working on that.
As opposed to that, I assume it is much harder for the ceylon team to get the entire company to support them. For example, even though vert.x 2.0 had support for ceylon, it's not clear for me if that is also the case for vert.x 3.0, and even if it is, ceylon still isn't featured as a main language on their landing page.
But they are working on an Intellij plugin, which I think will be available in ceylon 1.2. And that is the first step towards Android support.
Anyway, I hope both languages do well.
A year ago, I would have put Kotlin and Ceylon on the same level in potential but Kotlin seems to have gained some momentum this past year. On the other hand, I barely hear about Ceylon, even though it's now approaching 1.1.
https://github.com/jetbrains/workshop-jb
and some glimpses into the documentation you can get productive within a day or two.
It may not be as expressive as Scala but still is a huge improvement over Java (or even Groovy).
http://kotlinlang.org/docs/reference/comparison-to-scala.htm...
The other problem I had using Scala on Android is that the very nature of the Android SDK forces you to work in a way that is very Java-ish. There are some libraries that try to provide a nice Scala layer on the top of the Android SDK, but it never covers everything so you always end-up writing ugly Javaish Scala code.
Supporting Java 8 requires updating the vm & OS, which is difficult to do in the Android ecosystem. It may happen in the future but backwards compatability will be tough since the phone manufacturers lag so badly on platform upgrades. I'm not even getting into the Oracle v Google spat that may slow down adoption of a newer version of Java.
For that reason Kotlin is a lot more viable today than Java 8. Maybe someday Java 8 will make it to Android, but that day is definitely not today. Even after it is released in the newest devices, it probably won't be widespread for 18+ months.
edit: no one should downvote the parent question it is a legit technical ask without an obvious answer.
$ jdk-1.8-64/bin/javac -target 1.6 -source 1.6 LambdaTest.java
warning: [options] bootstrap class path not set in conjunction with -source 1.6
LambdaTest.java:16: error: lambda expressions are not supported in -source 1.6
Runnable r2 = () -> System.out.println("Hello world two!");
^
(use -source 8 or higher to enable lambda expressions)
1 error
1 warning
Trying to heed the error: $ jdk-1.8-64/bin/javac -target 1.6 -source 8 LambdaTest.java
javac: source release 8 requires target release 1.8There is a project that patches Java 8 bytecode and replaces all lambda invocations and method references with anonymous class instantiations. It's called RetroLambda and lets Android devs use Java 8 lambdas in their code. It does open a whole new pit of issues though.
https://github.com/orfjackal/retrolambda
Sounds like there might be some things that are missing or incomplete, but having lambdas and the Stream API would be a huge step forward.
These JVM based languages are able to support the latest and greatest features however because they end up compiling down to Java 7 byte code, which can in turn be converted to Dalvik/ART byte code.
Java 9 brings modules.
Java 10 has on its roadmap value types, JNI replacement, GPGPU support, new array model and whatever they might still consider.
If one assumes e.g. in comparison Apple will in 2 years have 95% of devices capable of running Swift 3 apps vs. 15% of Android devices capable of Java 8, much less 9/10 ... it could be quite a competitive disadvantage for Android, as well as argument for adopting a forward-looking JVM language dedicated to compiling to 1.6 bytecode if you plan to do Android development.
Like modularize it more so they can have a subset working on Java and make the compiler faster / better / more tooling support.
That would've been better with yet another JVM language. The community is splitting and splitting and still most people think in the same niche, but they always use their different syntax.
I mean kotlin does a lot of things like scala but still tries to be his own language and doesn't use as much fp as scala does. it also uses 'it' instead of '_' not sure why they came to 'it' also the data classes so much work around stuff, thats just aweful.
Hopefully Java will get more functional so that we don't get a too fragmented community.
P.S.: Yes everything has it's place i just dislike whats happening in the it, so that everybody wants to do his own thing instead of working together.
> Hopefully Java will get more functional so that we don't get a too fragmented community.
Java did so much harm to programming community, it basically destroyed reputation of strong static typing as something considered "fun". Maybe it's time to move on, to split into better, more modern, elegant and expressive languages.
I wouldn't call it "slightly better". It is much, much better. There aren't that much changes to your programming habits or architecture, but improvements which Kotlin brings are huge.
Absence of nulls, type-inference, top-level functions. All this would make a huge difference, not "slight" one.
Kotlin is an attempt at taking the other road: building an incremental language over Java. We'll see in a couple of years if that experiment is a success.
http://kotlinlang.org/docs/tutorials/kotlin-android.html
Which a) requires one use the IDE. Maybe not surprising from a company that sells IDEs, but it's not my dream environment. b) Even then, one is asked to manually "replace java kode with kotlin" (with help of a wizard). Couldn't we just get a script/function that'll set up a project targeting the desired Android API level?
It'd be nice if kotlin provided a script/command-line utility that basically allowed the equivalent of:
android create project -a Main -p hello \
-k com.example.app
-t android-15 -g -v 1.3.1
cd hello/
# Note that even android sdk is broken,
# one needs to manually change:
#
# runProguard false
#
# to
#
# minifyEnabled false
#
# in build.gradle
gradle build
# Start emulator (android avd...)
# possibly (re)start adb server
#
adb install ./build/outputs/apk/hello-debug.apk
I'm still figuring out the Android/java command-line/build workflow, but I suppose one should be able to drop the kotlin.jar somewhere, and add something to build.gradle. I've yet to find any documentation how how to do that (official or otherwise).Am I really the only one that wants a predictable, scriptable environment in which I can both initiate development from scaffolding supported by upstream, and have a reasonable grasp over the entire build process?
I mean, we all want to automate this for Continous Integration, right?
And other build tools: http://kotlinlang.org/docs/tutorials/build-tools.html
At least now I should be able to get a proper java skeleton, fix the build, add support for kotlin. Only missing piece would be a supported "pure" kotlin Android project/skeleton generator.
At some point I also looked at the Android example at the bottom of that page: https://github.com/JetBrains/kotlin-examples/tree/master/gra... -- that is also IDE centric, and hasn't been touched in a while. Which doesn't leave me very confident that it's been tested with Android 5.1 and/or 6 alpha.
I suppose I'll just have to push out a "howistart"-article if/when I figure out a process that is both easy and repeatable, and hope someone will help with filing bugs as it inevitably drifts towards being outdated as the android landscape changes :-)
I think it's more likely that we'll see Go, Dart, JavaScript, or even Swift become a first-class development option on Android.
Swift would be especially nice. How fantastic it would be to be able to use the same language to target the two most popular mobile platforms? Of course Swift is also probably the least likely since Google is still smarting from the Oracle/Java debacle. The last thing they need is another decade-long copyright infringement fight with the richest company in the world...
If you take a look at the public commit on the AOSP jack & jill repo, you can see that google is working on Java 8 integration : https://android-review.googlesource.com/#/c/150214/2/jack-te...
It is very surprising though, I would have expected Google to explore other options due to the hard back compatibility story and with Oracle ready to push this legal battle as far as possible.
As far as Swift on Android ? From a developer point of view, there would probably be far worse choices (one could argue that Kotlin would be a better choice, if only because of Java 6 as a target) but yeah even without considering the legal aspect, I doubt that Google would be ready to use a language managed by its direct competitor.
That would be a little foolhardy on Google's part, don't you think? Considering the ongoing 'API copyright' wrangle that is Oracle v. Google
It's certainly not a radical or nonconformist choice to make while designing a language. It might seem unusual to people whose experience is with C-style declarations, but it really is just replacing one well-known syntax with another, equivalent well-known syntax.
As for Groovy, it's barely statically typed so not really an option for me.
ints.filter { i -> i > 0 }.map { i -> i*i }
will use deferred execution. Is this correct? If so, why?I had a quick scan of the Kotlin repo, and I think it depends on the type that you start out with. The sequence stuff is lazy; the map stuff is eager.
ints.asSequence().filter { it > 0 }.map { it * it }
and then you can convert it to a concrete collection type with toList, toHashSet, toArrayList etc.FWIW, codehaus closed down. When was groovy "booted off"?
can Kotlin support 'Spring framework ?, if can, it is more attract for Java developer