6 ms·
This article misses something I feel is really very important: Kotlin is just Java! Like, granted, I'm probably a better-than-average developer, but I was turni
by eropple 9y ago
This article misses something I feel is really very important: Kotlin is just Java! Like, granted, I'm probably a better-than-average developer, but I was turning out well-factored, clean, readable, 100% Java-interoperable code in Kotlin in about a day. Over time I've added more Kotlin-specific stuff (like their way nicer-feeling collections APIs) but for real, it's just...Java.
But it's smarter Java. It gets out of your way. If you understand Java, the 1:1 mapping between Kotlin and Java is trivial. I can tell you what the auto-generated Kotlin code from the IntelliJ helpers is gonna look like when you convert Java to Kotlin and it's just...obvious? The only thing I have ever had even the slightest trouble with was how to take a var (which I understood immediately to be a backing field with getter/setter methods under the hood, both because the doc says so and because IDEA says "from getFoo/setFoo" when importing Java so it's an obvious intuitive leap) and apply a Hibernate Validator attribute only to the getter. It was a hole in the docs at the time, but I figured it out: `@get:Something()`. If that's the only thing that gets an experienced but largely out-of-the-game Java developer a little head-scratchy, this should be a slam-dunk type of thing for somebody who writes Java every day.
Maybe it's harder for Android. (I think you should write React Native for Android for basically anything you can--and I have, I released a Google Play app a couple weeks ago that I really should get around to marketing--because while I am down with Kotlin,I also like being able to actually share code everywhere.) But Java-to-Kotlin is a no-brainer, in my book, at literally any Java shop not targeting, like, Java one-dot-ancient.
- k__ 9y ago> Kotlin is just Java! Nobody cares. I mean, look at JSX, which is just JavaScript. Coming from all the crap templating languages pulled off the last 10 years it is basically god sent. Still people hate around and they always will, that's what we do, we lern stuff and if it gets obsolete, we want to keep it because it fed us for years.
- mixedCase 9y agoThe JSX thing is because we (as an industry) teach "separate your concerns" as gospel and naturally you're going to get some pushback, specially from the very numerous group of "by the book" developers. Scala was treated for a long time as "a better Java"; but Kotlin really is way more befitting of the title. There shouldn't be as much resistance.
- orclev 9y agoI never considered Scala a better Java. Scala was attempting to be a better language on the JVM, but you'd have to be tripping on something seriously heavy to think Scala even remotely resembles Java. Scala was basically the unholy love child of OCaml, and Haskell, with a tiny sprinkle of Java on top to make it play nicer on the JVM. I had high hopes for Scala, I'm a huge fan of Haskell, but I just couldn't bring myself to like Scala, it's an ugly language that ruins everything good in Haskell by polluting it with OO. Kotlin on the other hand, really is a better Java. If you take Java, remove all the biggest day to day headaches, change around the defaults to be sane (I.E. the default is what you want 90% of the time, instead of the other way around), and add in some functional inspired helpers, you basically arrive at Kotlin. The delegate system, the way they finally got rid of the need to make pointless getters and setters on the off chance you might some day want them and not want to refactor your entire codebase, making classes and methods public by default since that's what you want almost always, and making types non-nullable by default are all MAJOR improvements over Java, but not something completely alien to the Java way of doing things.
- buremba 9y agoYou know, there is a joke that 90% of the developers think that they're better than average. :)
- szemet 9y ago"90% of the developers think that they're better than average" Median. It can happen that 90% of programmers literally better than the average.
- mnm2 9y agoThe few bad/worse developers are then 10% and would have to be really bad
- emodendroket 9y agoIs that unbelievable?
- buremba 9y agoThis is part of the joke. It can be true but it's almost impossible to have this kind of distribution among developers.
- raverbashing 9y ago> It can happen that 90% of programmers literally better than the average. While mathematically true, in practice almost impossible
- raverbashing 9y ago> It can happen that 90% of programmers literally better than the average. While mathematically true, in practice almost impossible
- edem 9y agoThis comment is useless since you don't state anything, don't refute anything and add no value.
- 9y ago
- ebiester 9y agoWe had a few places where we had some headscratchers. First, it took a little time to get the hang of json manipulation. We got to a solution we liked, but a dynamically typed language like groovy has some advantages there. Closed classes by default can make some testing a little more difficult. We have continued using Spock rather than moving our tests to Kotlin, and there are a few places where we compromise our design until we can figure out a better way. (Yes. Dependency Injection and less coupling is the answer, alongside adding a level of abstraction in between third parties. The devil is in the details.) In general, we like it and are planning on expanding our use, but conversion has had its challenges.
- emodendroket 9y ago> First, it took a little time to get the hang of json manipulation. We got to a solution we liked, but a dynamically typed language like groovy has some advantages there. Does it? I really prefer JSON.NET's approach, which involves declaring models that represent your JSON, over dynamic "hope it's there" approaches.
- Guthur 9y agoFalse equivalence. You can static check this until you ate blue in the face but you still 'hope its there'. You would specify the contract for runtime checking like any sane engineer
- emodendroket 9y agoYes, but I don't have to worry about something like unintentionally spelling it differently on different lines, and in the case where I'm controlling both ends it is truly taken care of for me.
- eropple 9y agoWhat trouble did you run into with JSON? I just make Jackson objects as data classes and I'm done with it. Mucking with ObjectNode/ArrayNode is a bit annoying but not too bad, especially when you can map and collect. Was gonna say what you did about testing, but you have it, so, yeah. ;)
- prophesi 9y agoThe other really important thing: You can have both in one project. [1] You can gradually convert your existing Java project to Kotlin; there's even a menu item in IntelliJ to straight up convert a Java file into Kotlin. [1] https://kotlinlang.org/docs/tutorials/mixing-java-kotlin-intellij.html https://kotlinlang.org/docs/tutorials/mixing-java-kotlin-int...
- hiram112 9y agoI'd be very interested to see if this works out well in practice. We had the same hope for Scala - the idea being that the developers who were interested in using it functionally could do so in the more complicated parts of our application, but the 'rest' of the developers, many who were honestly either not capable or just not interested in picking it up, would be able to still use traditional Java. Unfortunately, Scala just had too many incompatibilities: things like Options instead of null or to call a Scala method in Java would require some confusing method call like new Function0<String> because that is how Scala converts to bytecode. And collections and immutable types never really worked back and forth very well. The final straw was when we had Thrift interfaces that simply broke if a project moved from Scala 2.10 to 2.11 without recompiling all the dependencies. But if Kotlin really is completely compatible with Java without too many show stoppers dragging down productivity, this could be helpful for a lot of larger enterprise shops which contain a small subset of engineers who want and can use the language to improve things (or simply don't want to work with old Java code and will jump ship if forced to do so), but still need to keep things simple enough so that the rest of the team can still be productive.
- nevi-me 9y agoI learnt Kotlin by taking an Android app which I had written in Java, and gradually converting it i to Kotlin, this was just after 1.0. I'm a solo developer, and I use K and J together on most codebases (about 10), and at this point I only ever create K files. Regarding interop, I think it's a valid claim that K is 100% J compatible. I think instead of arbitrarily mixing the two, maybe start with a single module, or with testing. I write a lot of JS, and have been planning on trying out Kotlin with JS, because at this point, taking a JS function and converting it to Kotlin results in code that's between 70-80% Kotlin (const to val, add return types, etc.) I'm personally convinced that Kotlin is a good language to learn if you know Java.
- muzani 9y agoIt's not that much harder for Android. In fact, with Anko, there's even more reason to pick it up for Android. The pain point in using Java is huge for Android because a lot of Android functionality adds more boilerplate.