10 ms·
Kotlin 1.1 Released with JavaScript Support, Coroutines and more
- grabcocque 10y agoWhat I like about Kotlin is it's what you might call a "pragmatic Scala", and could find a sweet spot between Java and Scala where its added expressiveness allows it to shine, but Scala's complexity and performance issues aren't in evidence to scare the development managers into staying with Java.
- Scarbutt 10y agoScala's complexity and performance issues Is Kotlin really faster than Scala?
- grabcocque 10y agoScala's build times are legendarily horrible. Kotlin has similar compile times to Javac.
- pjmlp 10y agoThey are working on improving them though, specially with Dotty. In any case they aren't as bad as C++ (at least until modules arrive).
- smitherfield 10y ago> In any case they aren't as bad as C++ Speaking as a fan of Scala, I find that scalac takes a noticeable amount of time even to compile trivial Hello World-type programs. Huge C++ codebases like Chromium or Boost take ages to compile, but I seriously doubt a comparable Scala codebase would be faster.
- pjmlp 10y agoI only dabbled a few times in Scala, but I do regularly use C++ on some side projects. Do Scala compilation times get measured in hours? Just the other day I gave up compiling Cocos2D-X, after it crossed the one hour threshold on my humble dual core, 8GB.
- brianwawok 10y agoWell Scala programs only get half compiled at command time, the other half is JIT at runtime. But no not hours bad.. but say a 3 minute partial compile for a 1 line change is enough to kill your dev cycle. (Not sure it is 3 minutes bad for most projects these days, but its very hard to have a 2 second Scala compile)
- pkolaczk 10y agoYou get much better compile times if you keep scala compiler running in daemon mode (in SBT or IDEA; AFAIK Gradle can't do this yet), so it gets more benefits from JVM HotSpot. It makes a tremendous difference (up to 10x) on larger code bases and in fact, I often get 1-5s incremental compile times on a 20 kLOC codebase. Another trick is to modularize the project and enable parallel compilation to speed up compiling everything from scratch. As for C++ compile times, the major culprit are templates. Changing a single line of the implementation of a template requires to recompile all code using that template. Scala does not have this problem, because it has generics for most of the things that C++ templates are used, and generics support separate compilation.
- brianwawok 10y agoDaemon does help a bit. Gradle definitely has a daemon: https://docs.gradle.org/current/userguide/gradle_daemon.html https://docs.gradle.org/current/userguide/gradle_daemon.html I think in Scala you can do similar "must recompile all" if you do things like change a global implicit. > I often get 1-5s incremental compile times on a 20 kLOC codebase 20k is still toy project size though. Try incremental compile with 100k or 200k LOC. It gets bad.
- robertlagrant 10y agoI get what you're saying, but I wouldn't refer to that as a performance issue without any context.
- Nullabillity 10y agoIt hasn't been a big issue for me so far, but Kotlin often favours fast and compact where Scala favours generic and beautiful. For example, in Scala, nullable references are just another monad object implemented in plain Scala, while in Kotlin they have a special syntax around Java's null pointer.
- meddlepal 10y agoI've been very happy writing Kotlin backend code for the last fourteen months or so. Definitely excited. It's an awesome JVM language.
- agumonkey 10y agoI'm investigating Kotlin. Do you have references, blogs etc to suggest ?
- Larrikin 10y agoThrough this blog https://antonioleiva.com/kotlin/ https://antonioleiva.com/kotlin/ And his book I was able to become fairly productive in the language in only a few weeks. I was familiar with Scala however. The automatic conversion of java to Kotlin in Intelli J's IDEs also helped immensely.
- meddlepal 10y agoFor the most part I found the official Kotlin reference documentation to be excellent and more than enough to move from a strong Java and Groovy background. I follow /r/kotlin as well. Advanced idioms and stuff I've just picked up looking through GitHub repositories. What I really like about Kotlin is just about everything "works" as it should or you can usually write a Google search that will reference Stack Overflow. I don't have to dig much to find answers and in the absolute worst case I can just drop back to Java and do it the classic way.
- sandGorgon 10y agowhat backend framework are you using ? i have been pretty interested in trying out spring boot 5 or vertx
- meddlepal 10y agoVert.x though recently I switched back to Dropwizard for a prototype... it works mostly fine, but I think I've kinda fallen in love with Vert.x I think the only thing I find really annoying about Vert.x is the lack of built-in JSON -> object binding. I've written some cheap glue code to fix that though.
- netcraft 10y agokotlinjs is very interesting to me - anyone have experience with writing kotlin and typescript and can compare?
- WkndTriathlete 10y agoA few weeks ago I wrote the same application four times in four different JVM languages: Java, Groovy, Scala, and Kotlin, with a particular focus on the application using functional techniques and types as well as being reactive. I also included as goals complete test coverage with a preferred test framework from each language and complete build tooling, all within a single Gradle project. The only significant sources of variance were the following: a) Groovy's support for functional programming is starting to show its age. It worked with everything, though. b) The Scala 2.12 compiler has at least one bug that appears to affect its interaction with Java 8 lambdas (in particular, in at least one case expr.method() and (expr).method() will not pass the compiler's typecheck, but { val x = expr; x.method() } does. (All three pass IntelliJ's typechecker for Scala.) Outside of this (aggravating) issue and slower build times, it did work. c) Java works well with everything but ends up being quite verbose, especially in regards to a functional programming style (no surprise there). d) Kotlin (1.0) works well with everything and is relatively succinct except for Mockito due to everything defaulting to 'final' - but it appears that Kotlin 1.1 fixes this with a compiler plugin. Based on my experience with all four languages, I would definitely try adding Kotlin to projects. It seems to be surprisingly mature and stable given how much less time it has spent in development (relative to the other three languages.)
- tutanchamun 10y agoWhat functinal techniques did you use? Only higher order functions or did you go all the way to applicatives, monads (maybe even free) etc.? btw: is the source code available somwhere? Would be interesting to see a comparison between the languages.
- meddlepal 10y agoI'm interested in the comparison code as well if it's available.
- Scarbutt 10y agoCurious, if you were aiming at writing in a functional programming style, why didn't you try Clojure?
- vbezhenar 10y agoKotlin for me is Java made right. It's not complex, it has awesome interoperability with Java, it uses JDK, not reinventing its own wheels and it has everything I need from modern language. But it seems that Jetbrains has its own vision for Kotlin being a completely independent language. So while it works for me right now, I'm not sure if it will work in the future. They are going native and it'll bring a lot of changes, for sure. Honestly I would prefer it to stay as Java enhancer, as I'm not interested in Native and I need very little JavaScript interoperability, if any (probably just translating some common code between backend and frontend). But we will see, I don't want to sound too pessimistic. Kotlin is the best language I've used so far.
- yole 10y agoEven with Kotlin Native in mind, we have no plans to break Kotlin's backwards compatibility guarantees, and we do plan to support the new JVM features such as value types. So if Kotlin works well as a Java enhancer for you today, it will only work better in that role in the future.
- cutler 10y agoPerhaps the bigger issue here is fragmentation. Here you are, a young language with a lot of promise whose primary appeal is Java interop and whose target market is enterprise Java and already you're dividing your efforts to offer something which your target market will likely have zero interest in. Why not wait until you have real market share in the job market and only then worry about native? Kotlin is a very niche language. That's it's appeal.
- cheriot 10y agoI suspect some combination of 1) It's hard for a new language to get traction. Lower odds that a new startup! They see so many ruby and python shops adding Go to their stack and want to compete in that space. Kotlin's biggest market seems to be android devs and competing with Go puts them in the datacenter. 2) IDEA's IDEs have a better value proposition to devs working with statically typed languages. Appealing to current Java devs builds the Kotlin ecosystem, but appealing to dynamic language devs expands IDEA's customer base more.
- sandGorgon 10y agoKotlin is not just for android apps. Kotlin is getting first class support on next generation Spring web framework with functional programming support - https://speakerdeck.com/sdeleuze/functional-web-applications-with-kotlin-and-spring-5 https://speakerdeck.com/sdeleuze/functional-web-applications... it's almost done with first class support for vert.x which is a high-performance reactive webframework https://github.com/vert-x3/vertx-kotlin-common https://github.com/vert-x3/vertx-kotlin-common The reactor project (erlang for the jvm?) is building first class support for kotlin https://github.com/reactor https://github.com/reactor I think its going to be a great year for building backend systems on jvm.
- asitdhal 10y agoKotlin is the best option for Android apps. There are many languages for backends and tons of libraries. But there is hardly any substitute of Java in Android(if you don't consider JS solving every problem in this planet). If JetBrains only concentrate on building an ecosystem for android, it can become "the real Swift for android". I built a dummy app for android in Kotlin. It was great. The same thing I tried in Scala(it didn't go very well).
- dep_b 10y agoI wouldn't touch Java if I could write something in Kotlin instead. I'm using Swift on a daily base and while it still has it's issues (compile times, breaking changes) it's a great language to work in and extremely similar to Kotlin. Better type safety means less crashes.
- jbmorgado 10y agoDoes this mean we can now build a full React Native app using only Kotlin?
- bashor_ 10y agoWe going to publish more materials about JavaScript in the next few weeks. Including with using React.
- swsieber 10y agoWill there be anything about angular? Also, is it possible to set up kotlin source code in gradle to compile both to JS and the JVM at the same time? I'm specificially thinking that it'd be nice to "share" code between front and backend for some logic and data model definitions.... I think that'd be a killer feature.
- vorg 10y agoIf you can, make sure you write your Gradle build scripts in Kotlin also (possible since Gradle 3.0 was released 6 months ago) instead of Apache Groovy, then Kotlin will be the only language you need for anything!
- danneu 10y agoFor fun, I've been working on a simple hobby web server in Kotlin that wraps Jetty: https://github.com/danneu/kog https://github.com/danneu/kog I think Kotlin is the statically-typed language I've been waiting for, especially with the team's interest in native and JS targets.
- Scarbutt 10y agoDo you have any opinions on Kotlin vs Clojure? are you liking Kotlin more?
- danneu 10y agoI think static typing + solid IDE support is too useful to pass up, and that's what Kotlin has. But Kotlin also has simplicity that, for example, Scala doesn't. I tried Clojure after spending a couple months with Scala and giving up, and then I used Clojure fulltime for 3+ years. Eventually, I felt like I was hitting a ceiling with Clojure since it lacked good static analysis. I moved to Node because I felt like, if I'm going to use a dynamically-typed language, I might as well use the ubiquitous one. Also, Clojure was a hard sell to other developers I would meet. What Clojure does have is an ecosystem of simplicity that I hope the Kotlin ecosystem will adopt. For example, compare ztellman's http://aleph.io/ http://aleph.io/ (Clojure) to Java's Netty or to the somewhat mind-numbing https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/CompletionStage.html https://docs.oracle.com/javase/8/docs/api/java/util/concurre.... And compare Clojure's Ring to any Java web framework. Even Spark, Java's simplest option afaict, doesn't have real middleware, just before/after "filters". That's why I went with the `(Request) -> Response` signature over the `(Request, Response) -> Unit` signature. There's also ClojureScript's integration and tooling which are pretty impressive these days while Kotlin's JS support is still fledgling. Though these are the impressions of someone who has only been using Kotlin for a few months without a Java background. And it's not like anyone should be using my lil framework in production, it's just a hobby.
- cutler 10y agoClojure and Kotlin are, for me, the brightest stars in the JVM sky. However, I fear Clojure adoption has peaked at its current low rate probably because it was never aimed at the corporate Java world as Kotlin is. Clojure appeals more to the software artisan which is a valuable niche in itself but its syntax, which is its strength, is so different from Java's that I think it is rarely seen as an alternative to Java.
- mwcampbell 10y agoI wonder how Kotlin's JavaScript backend compars to Scala.js in Li Haoyi's list of fundamental reasons for betting on Scala.js: http://www.lihaoyi.com/post/FromfirstprinciplesWhyIbetonScalajs.html http://www.lihaoyi.com/post/FromfirstprinciplesWhyIbetonScal... I have a few concerns about Kotlin's JS backend: How much can the complete JS bundle be optimized by an advanced whole-program optimizer like the Google Closure Compiler? Kotlin for JS has no reflection, and I think JetBrains should not look into that as they said they are. But is there powerful compile-time code generation instead, e.g. through annotation processors? Is there, or will there be, a healthy ecosystem of pure-Kotlin libraries that can be used with both the JVM and JS?
- bashor_ 10y ago> How much can the complete JS bundle be optimized by an advanced whole-program optimizer like the Google Closure Compiler? JavaScript backend generates code understandable by static analyzers so it can be optimized. Anyway, we going to continue works in this area in near future. > Kotlin for JS has no reflection, and I think JetBrains should not look into that as they said they are. But is there powerful compile-time code generation instead, e.g. through annotation processors? Why do you think that reflection is a bad idea? Honestly, we don't have a final decision about it, it requires investigations and discussions. Note it's very important for us to have an ability to provide good tools (e.g IDE support) for features. > Is there, or will there be, a healthy ecosystem of pure-Kotlin libraries that can be used with both the JVM and JS? We will work on it.
- mwcampbell 10y ago> Why do you think that reflection is a bad idea? OK, reflection isn't necessarily a bad idea. Clearly development tools need it, including future tools that run in the browser (e.g. an in-browser IDE). But I think that applications that are not development tools should not use reflection, because it interferes with static optimization, as the article that I linked in my original comment explains. So most libraries should probably not use reflection either. That means we need an alternative to reflection. For example, chapter 10 of _Kotlin in Action_ uses reflection to implement a serialization library. I think it would be better to use build-time code generation for that, even outside the JS use case (e.g. reflection interfers with optimization of Android app packages with ProGuard). Edit: By the way, thanks for taking the time to respond.
- afastow 10y agoThe post specifically mentions using Kotlin Javascript to develop React applications. Are there any simple examples out there showing this? I'm not seeing any after a quick google search and look through the docs. Developing a modern frontend app is complex enough with Javascript or Typescript. It's pretty hard to ask people to figure it out from scratch in Kotlin by just saying that it's possible but not showing how.
- Teedee753 10y agoIt was mentioned on the Kotlin slack that Jetbrains would make some examples available within a few weeks on using Kotlin JS including using it with React.
- curyous 10y agoWhy couldn't they have used "func" for functions, like so many languages do, instead of "fun"?
- richard_todd 10y agoI don't think of 'func' as a standard. Off the top of my head, you can see "defun", "fn", "def", "function", and on and on in various languages. I don't see much agreement across the board.
- netcraft 10y agodoes anyone know of a place that compares syntax like this across languages? I've found myself often wondering if there is consensus for certain features or syntax.
- richard_todd 10y agoNot exactly, but on rosettacode.org (http://rosettacode.org/wiki/Rosetta_Code http://rosettacode.org/wiki/Rosetta_Code) you can see tons of languages implementing the same toy programs, so they will often be using comparable language features in the process.
- chocolateboy 10y agohttp://rigaux.org/language-study/syntax-across-languages.html#FnctnFnctDfnt http://rigaux.org/language-study/syntax-across-languages.htm...
- cdelsolar 10y agoBecause it's fun.
- dalailambda 10y agoIf using 4 wide space/tabs, the function body will line up with the function name when using "fun". Maybe not the reason, but it is a reason.