12 ms·
Kotlin, the Swift of Android
- krschultz 12y agoKotlin looks like a very nice addition to Android ecosystem. It meshes pretty seamlessly with Java and takes a few of the obvious syntactic pains away. I think as the Android build system improves using other languages will become more common.
- morazow 12y agoScala for Android, https://news.ycombinator.com/item?id=8192406 https://news.ycombinator.com/item?id=8192406
- V-2 12y agoI gave up trying to set it up for Android. It just sucks, and there is nothing but random blog entries on how to get it done. If someone pointed me to reliable resources on how to get it to work, I'd appreciate it very much (as I like the language itself)
- eeperson 12y agoHave you looked at the usage guides for the various plugins [1][2]? [1] https://github.com/jberkel/android-plugin/wiki/getting-started https://github.com/jberkel/android-plugin/wiki/getting-start... [2] https://github.com/pfn/android-sdk-plugin#usage https://github.com/pfn/android-sdk-plugin#usage
- V-2 12y agoI can't remember anymore what I tried and what I didn't :) At the end, I mostly tried not to bang my head against the wall. Anyway, even your second link stresses: "The primary IDE recommendation is IntelliJ, not Android Studio nor Eclipse". My IDE of choice is Android Studio, and it not being particularly recommended is a red light to me already. Maybe I'm just traumatized. I'm surely lazy. I wish Google made Scala support for Android official and integrated it seamlessly.
- eeperson 12y agoThat recommendations is strange. The directions just have you include an almost standard version of the IntelliJ plugin for SBT (it is the standard plugin with an extra bug fix). So, any of these IDEs should work without issue. You just need to set up the standard SBT plugins for integrating those IDEs.
- Nullabillity 12y ago> Anyway, even your second link stresses: "The primary IDE recommendation is IntelliJ, not Android Studio nor Eclipse". My IDE of choice is Android Studio, and it not being particularly recommended is a red light to me already. Maybe I'm just traumatized. Seriously? Android Studio is just a stripped down IDEA with an extra plugin anyway. If you already use AS, there is zero reason not to just import your config into IDEA instead.
- PudgePacket 12y agoJust a side question, the author mentions method count as a downside of introducing alternate JVM languages. Does the method could slowdown/bloat apps somehow?
- thefreeman 12y agoNo, but older Android versions have a maximum 64000 method limit. I think it has been fixed for later versions, but I am really not sure. There have been some blog posts about Facebook's (controversial) attempts to work around this limit: https://www.facebook.com/notes/facebook-engineering/under-the-hood-dalvik-patch-for-facebook-for-android/10151345597798920 https://www.facebook.com/notes/facebook-engineering/under-th...
- cypher543 12y agoAndroid 4.0 introduced a new set of Dalvik instructions that supported larger methods IDs, but they were never used and were eventually removed. ART may have lifted the method limit, but I haven't seen any specific mention of it.
- jc4p 12y agoART does not lift it. I was at the I/O session where the ART team explicitly stated that.
- ZoFreX 12y agoNot older. All. It's a limitation of the file format, not the runtime. It's a common misconception that it's fixed in later versions, because Facebook ran into a very similar (but different) problem that is fixed on newer devices (the one you linked to).
- masklinn 12y agoIt's way more fucked up than that, Dalvik is limited to 65k invocable methods per dex file: https://medium.com/@rotxed/dex-skys-the-limit-no-65k-methods-is-28e6cb40cf71 https://medium.com/@rotxed/dex-skys-the-limit-no-65k-methods... > You can reference a very large number of methods in a DEX file, but you can only invoke the first 65536, because that’s all the room you have in the method invocation instruction. > […] the limitation is on the number of methods referenced, not the number of methods defined. If your DEX file has only a few methods, but together they call 70,000 different externally-defined methods, you’re going to exceed the limit.
- seanhandley 12y agoYou can write shared functionality in pure Ruby using RubyMotion then write your view layers for iOS and Android and have them each compiled correctly to native apps for each platform. I'd rather use Ruby than Swift or Kotlin.
- evilduck 12y agoEventually you can write shared functionality in pure Ruby. RubyMotion 3.0 for Android is still in the early beta phase and it probably won't be publicly available before the end of the year (it's not been announced, but I've seen the beta and that's my guess).
- klibertp 12y ago> I'd rather use Ruby than Swift or Kotlin. Yeah, but there are people who'd rather use Haskell, Clean, Agda or Idris. Kotlin, Swift, Rust and other such things seem like a reasonable middle ground from this perspective.
- V-2 12y agoI have been fiddling with Kotlin for last few days. It is trivial to get it working in Android Studio, which is a plus already. It's not nearly as verbose as Java, and for one thing, it gives me LINQ that I've been missing from C#.
- manojlds 12y agoFor C# devs, Xamarin is a good choice I believe, despite being paid.
- V-2 12y agoI've had opportunity to play with it (at work), but given the price, not a likely choice for my hobby projects. It's not without its drawbacks, either. Since it's not native development (for Android), we 'e adding more moving parts into the equation. And, for instance, most of the sample apps for Xamarin.Forms wouldn't even build when I tested Xamarin. I had to fix folder paths (to Android SDK) manually. The product is superb, but Android is under rapid development and Xamarin folks will always have to play catch up with them. And in meantime, weird things - all sorts of incompatibilities - are bound to be popping out.
- UK-AL 12y agoXamarin Forms is really new. Xamarin Android(Accessing native Apis via C#) is quite stable.
- sitkack 12y agoHow well does the bytecode convert with RoboVM?
- talloaktrees 12y agoKotlin works very well with robovm. In fact, there is a game written in kotlin on the iOS store called True Fool that uses robovm
- Pxtl 12y ago
- richardwhiuk 12y agoIt would be nice if more of this was folded into Java itself, rather than existing as a new language - as the author notes a lot of it is in Java 8.
- hhariri 12y agoJava 8 does introduce a few features that are available in Kotlin, but AFAIK Java 8 won't be available for Android for some time. In addition, Kotlin makes a lot of constructs more succinct, including but not limited class definitions. So it's not only about what it adds, but what it "takes away" too IMHO.
- higherpurpose 12y ago> AFAIK Java 8 won't be available for Android for some time Pretty sure it will never be available on Android. Best case scenario Google moves away from it. Worst case, it will add some new, similar features to Dalvik VM. But I doubt they are considering adopting Java 8.
- dtech 12y agoDo you have any basis for these claims? Java 8 contains many useful language improvements and Google has shown with Java 7 that it will adopt these (albeit incredibly slowly)
- frowaway001 12y agoIt has only adopted Java 7 features which are either syntactic sugar or library extensions. (E. g. everything where the Java class file version wouldn't have mattered anyway). Java 8 (and Java 9 and Java 10) are completely different, with huge, mandatory changes to the class file format and the virtual machine.
- rst 12y agoRemember the Google/Oracle lawsuits over the use of Java technology in Android? Bringing in JVM changes from newer Java releases risks giving Oracle grounds for another lawsuit (covering the patents and whatever copyrights may apply to the new features), and it's not likely Google wants to run that risk. (This is why the Java 7 features that they have adopted are the "syntactic sugar" that doesn't require JVM changes, and leaves the code running in the phones as-is.)
- pavlov 12y agoIt's an important point in Kotlin's favour that it's developed by JetBrain, the company that makes Google's official Android IDE. If/when Google decides it's time to sanction a Java replacement on Android, the language designed by their tool provider seems like the obvious choice.
- mike_hearn 12y agoIt's not only about Android. Kotlin is one of the few languages that's developed hand in hand with IDE support. That means you've got Java-class IDEA support for the language, including (interestingly) a Java to Kotlin converter tool! It's not like many languages where you end up having to sacrifice all your nice refactoring tools and libraries to use it. For this reason alone Kotlin is a natural upgrade path for many Java shops.
- frowaway001 12y agoHow is the Eclipse support coming along?
- V-2 12y agoBy the way, this converter is not without flaws. Eg. if you convert an Activity written in Java to Kotlin, method signatures do not match (because in Kotlin it should be Bundle? instead of Bundle and so on, since they are all nullable), and that results in baffling error messages that you're trying to override non-existent methods, it's not easy to figure out what's wrong.
- mike_hearn 12y agoLike much of Kotlin, it's sort of rough. I would not want to recommend it to anyone for an industrial project today, it's just not 1.0 material. For example the Kotlin API (extensions to Java classes mostly) is hardly documented at all.
- hhariri 12y agoMinor correction. We don't make Android Studio. Android Studio is based off of the IntelliJ IDEA platform, which is what we develop.
- talloaktrees 12y agoI've been looking a lot at Scala and kotlin recently. Other differences aside, Kotlin has an 800kb runtime compared to Scala 2.11's 11mb runtime. That's quite a difference
- frowaway001 12y agoHow do you come up with 11 MB? Even the whole library jar file which is much more than just the runtime is only 5.5 MB. But even then it doesn't matter anyway. Android apps are ProGuarded before deployment (regardless of the language used) and the overhead in Sclaa's case is a few dozen kBs.
- lvillani 12y agoThe less code has to be converted to the DEX format, the better. Sure, build tools have improved somewhat (incremental DEX compilation comes to mind) but, still, every time I pull in some rather big (~1 MB) .jar file in my project I get noticeably longer build times for non-production builds. With a 11 MB dependency, even production builds take considerably more time to complete and that gets in the way when you want to test the app on a production setting and you have to wade through a lengthy build process each time you fix a bug.
- frowaway001 12y agoThere. Is. No. 11. MB. dependency. And even if there was, it wouldn't matter because it would be done once and then deployed directly on the development device. Really, can we just stop making stuff up?
- lmm 12y agoYour final app with Scala may well be smaller than with Kotlin - Scala makes very high level abstractions possible, and while the standard library is large, anything you don't use won't be included in your app. Kotlin always struck me as a bit halfhearted - if I'm going to go to the effort of learning a new language, I want one that gives me a real power boost, not just a small incremental improvement.
- wasyl 12y agoDoes anyone have some performance comparison betweend projects written in pure Java vs straightforward Kotlin? I don't feel that method count is performance measure, I'd rather see some fps, method calls/sec or something like this. Or I'm wrong about method count?
- mike_hearn 12y agoThere was someone from JetBrains doing profiling and chatting about it in #kotlin (freenode IRC) the other day. Oddly, he found some things got faster in Kotlin for no obvious reason. Some JVM optimisation magic, I guess. Kotlin is a much more pragmatic language than many such new ones. They are building it for use in their own products including performance sensitive products like IntelliJ. For example it has an inline method attribute. This may seem remarkably low level for a modern JVM based language intended for industrial use, but there's a point to it: it lets you use lambda functions and misc features that rely on them without extraneous memory allocations. Applied consistently this sort of thing can make the difference between "a lovely language that's too expensive to use" and "a lovely language that is deployable". It's not auto-inferred because otherwise you wouldn't be able to make libraries that have stable ABIs with Kotlin. Generally they seem to be targeting zero performance degradation over Java even when using the advanced features, which is nice to see.
- orangy 12y agoYep, I agree. Mostly because it was me digging into JMH :) Indeed we are measuring and optimising. This is still early work in progress, but we have some good results already: inline fun calc<T, R>(value: T, fn: (T)->R): R = fn(value) inline fun identity<T>(value: T): T = calc(value) { it } // This is optimised down to loading constant value 1 into variable x val x = identity(1) Besides having nice syntax for lots of everyday things Java developers are doing, we want to provide means for doing it effectively, clearly and maintainably.
- simplestyle 12y agoHow does Kotlin compare to Groovy for Android development? Are they similar beasts when used for Android development, as in they both need to import their runtimes?
- masklinn 12y agoThe article touches upon that: Kotlin has a runtime you need to import, but it's significantly lighter-weight than Groovy's or Scala's, and the method-count overhead is relatively low (half that of Guava without proguard). Looking at the relevant jars, groovy 2.3.6 is 4.3MB[0] while Kotlin 0.8.679 is 353KB[1] (there's also a 503KB kotlin-stdlib, not sure what the comparison should be to but it compares very favorably even including both) For other references, Scala 2.11.2 is 5.3MB and Clojure 1.6.0 is 3.5MB[3] [0] http://mvnrepository.com/artifact/org.codehaus.groovy/groovy/2.3.6 http://mvnrepository.com/artifact/org.codehaus.groovy/groovy... [1] http://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-runtime/0.8.679 http://mvnrepository.com/artifact/org.jetbrains.kotlin/kotli... [2] http://mvnrepository.com/artifact/org.scala-lang/scala-library/2.11.2 http://mvnrepository.com/artifact/org.scala-lang/scala-libra... [3] http://mvnrepository.com/artifact/org.clojure/clojure/1.6.0 http://mvnrepository.com/artifact/org.clojure/clojure/1.6.0
- kryptiskt 12y agoSwift has algebraic data types and pattern matching, this doesn't. It just seems to be Java with a paintjob and some bells and whistles tacked on. I don't see the point of such a timid new language.
- 21echoes 12y agoliterally the third sentence: "For the desperate and adventurous there are the JVM alternatives like Scala and Groovy, but using them with Android is expensive: importing a language means importing the whole runtime, which is a nightmare for the package size and method count"
- emmanueloga_ 12y agoCeylon does better in this regard [1]. Ceylon and Kotlin share some features and aesthetics but Ceylon provides a lot more power over java8 than a nicer syntax for lambdas, e.g. algebraic types. I'm also excited about Ceylon's module system [2]. 1: http://ceylon-lang.org/documentation/1.0/faq/language-design/#language_features http://ceylon-lang.org/documentation/1.0/faq/language-design... 2: http://ceylon-lang.org/blog/2013/04/11/about-modules/ http://ceylon-lang.org/blog/2013/04/11/about-modules/
- lvillani 12y agoI tried Kotlin to write the first version of a small internal application used at the company I work at. On the plus side is IDE support and the fact that you can mix and match Kotlin with existing Java code. In the end though, I found the syntax "funny" in some places and slightly less verbose than Java but not enough to justify using it. The underlying Android API is so verbose that Kotlin by itself is nearly useless. We ended up dropping Kotlin and rewriting the thing in Java. In terms of lines of code both versions are nearly the same.
- gruvector 12y agoKotlin is very similar to Scala, but far less ambitious and not as focused on functional programming. In fact there have been various posts pointing out the similarities between Scala and Swift. It's rather pragmatic but there hasn't been much interest in it so far. Perhaps things will pick up after hitting v1.0. Pitching it as a Java substitute for Android would be a clever move. Java 8 is a poor substitute for Kotlin or Scala, and on Android you're stuck on even more archaic syntax. I'd be glad to see Kotlin replace java on Android.
- higherpurpose 12y agoGoogle really needs to begin rewriting all Android APIs in Go. Not an easy task, but beats doing nothing, and also using something like Kotlin to make Android development slightly better.
- gruvector 12y agoGo is pretty low level compared to (even) java, not much of a win in terms of expressiveness or error handling. Seems like a lot of effort with minimal benefit.
- vorg 12y ago> Go is pretty low level compared to (even) java I've found Go and Java to be at the same level of abstraction. Go has interfaces and structs, but leaves out implementation inheritance because its authors feel that's one of Java's bad points. Go also leaves out method overloading which causes us to think hard about what to name the numerous methods. I don't know about the suitability of Go for Android though. Does Google have a secret project going on?
- LeicaLatte 12y agoClickbait?
- dodyg 12y agoJava 8 is not coming to Android anytime soon or ever. Kotlin is quite a nice alternative language for the platform. And the IDE support is superb.
- benjamins30 12y agoDoes this have the interactive programmer-friendly tools that Swift has?
- rsynnott 12y agoIt doesn't have anything like Playgrounds, but, as it's from Jetbrains, it does have very good IntelliJ support.
- serge2k 12y ago> This means that if text2 is null, the replace() method call is ignored and no NullPointerException is thrown. I don't understand why this is preferable.
- tjdetwiler 12y agoIt's intended to be shorthand for: if (text2 != null) { text2.replace() } Essentially they're moving support for @Nullable and @NotNull into the language and compiler. https://www.jetbrains.com/idea/documentation/howto.html https://www.jetbrains.com/idea/documentation/howto.html
- izolate 12y agoA lot of these things are already in Dart, which has a much nicer syntax. If they're going to switch from Java, I'd want them to choose Dart.
- seanmcdirmid 12y agoDart supports shared memory multi threading?
- tkubacki 12y agoDART has Erlang style actors that support concurrent threads of execution - so yes. Shared memory no AFAIK, but Dart seems to have nicer syntax.
- seanmcdirmid 12y agoIf dart doesn't support ordinary threads, it might be meant for the web and not as a language for writing android apps.
- Void_ 12y agoAre there any projects for Swift to JavaScript?
- aikah 12y agoAny reason to use this over Groovy ? Will Groovy has a few drawbacks, i found it much simpler and easier to use than scala.I personnally prefer a quick java over something that has to much features.Anybody tried both and can compare?
- hhariri 12y agoOne reason would be if you prefer static typing.
- hellrich 12y agoIn recent Groovy versions you can have type checking or even static compilation by annotating your code.
- gruvector 12y agoGroovy performance is pretty poor in general and is mostly used for writing build scripts. It's a scripting language whereas Scala and Kotlin are better suited to writing large systems. Groovy seems to have stagnated outside of its use with gradle, whereas Scala continues to grow.
- rufugee 12y agoI'm curious...why do you say it has stagnated? Seems to still be pretty popular...especially in the gradle and grails spaces. I've done quite a bit of groovy and have really enjoyed it. After years of doing java, and then years of ruby, and then trying to go back to java, I really struggled with rationalizing the move to myself given the immense amount of extra work java required to do anything productive. Groovy made the jump palatable, and in many ways I prefer groovy to ruby. That said, I haven't written any code which is particularly performance sensitive yet. However, groovy now has @CompileStatic, so you can statically compile the perf sensitive bits. I'm sure that doesn't completely solve the problem, but it's an option. I really do hope Kotlin succeeds thought. Having something in the middle of groovy and scala syntax-wise with no performance concerns and the great java integration groovy brings would be spectacular.
- knwang 12y agoCan Swift be the Swift of Android?
- V-2 12y agoExtension functions: "For those familiar with Objective-C, this is similar to categories." Or just the same as extension methods in C#...
- bad_user 12y agoAndroid apps tend to be compressed for distribution by means Proguard and Pack2000. Not perfect, but it does tree-shaking and so normally you pay only for what you use. I don't really buy the small JAR size argument. In a real project, you care about not reinventing the wheel, so you end up importing needed dependencies anyway, like from apache commons or guava, or stuff for serialization/deserialization, or whatever - I would rather have a couple of hundred KBs extra than having bugs or spending effort on reinventing the wheel. Scala's library for example is pretty big (can't remember the size, 10 or 20 MB?), but it has things I want in it and with tree shaking it can be translated in a dependency of very reasonable size (couple of hundred KB), a technique which also makes feasible Scala.js, a Scala to JS compiler.
- u124556 12y agoBuilt in Singletons? I'd like to see built in Dependency Injection instead.
- niutech 12y agoNope, the Swift of Android is called Xtend: http://blog.futurice.com/android-development-has-its-own-swift http://blog.futurice.com/android-development-has-its-own-swi...