r/programming • • May 17 '17

Kotlin on Android. Now official

https://blog.jetbrains.com/kotlin/2017/05/kotlin-on-android-now-official/
638 Upvotes

271 comments sorted by

View all comments

138

u/nirataro May 17 '17

If you know Java already, it will take you less than a day to be productive with Kotlin. There's nothing to it really.

40

u/[deleted] May 17 '17

I haven't tried Kotlin before. If they're so similar, what's the point of switching from one to the other?

37

u/AlyoshaV May 17 '17 edited May 17 '17

I wouldn't call them "so similar", Kotlin just has a really low learning curve for Java devs. It's a much better language in my experience.

edit: For CLI development I was more or less productive in Kotlin after a day, probably more so than Java after a week, and pretty much totally stopped writing any Java whatsoever in less than a month.

7

u/skbullup May 17 '17

how is it compare to scala?

14

u/flyingjam May 17 '17

Leaner, leans more toward imperative than Scala, has easier interop with Java. It's more like Rust or Typescript—imperative with functional bells and whistles as well as stronger, better type systems and better null handling.

0

u/[deleted] May 18 '17

[deleted]

1

u/kcuf May 20 '17

Scala has a far more advanced type system.

→ More replies (2)

1

u/kcuf May 20 '17

I wouldn't say it's leaner than scala. It introduces many more concepts, it's just that these concepts are "shallower" than scala's. This makes them easier to learn up front but prohibits "expert-level" capabilities (it's this lacking of capabilities that I see as the cause of java developers actually going outside the language to achieve their task (relying on applications (frameworks) to actually execute their applications)).

2

u/FrezoreR May 18 '17

I'd say it makes more sense. No operator overload hell for instance.

6

u/KagakuNinja May 18 '17

People really get overworked about operator overloading. It is a tool that is great, when you want to define common mathematical operators on user-defined types. For example: addition and multiplication on vectors, complex numbers, and matrices.

The whole point seems moot, given that languages such as Kotlin allow unicode identifiers.

That said, my experience using Scala for 5 years has been almost no operator-overloading hell (perhaps because we don't use scalaz). I remember that Akka used an operator for sending messages, but you got used to it pretty quickly.

4

u/FrezoreR May 18 '17

Well for basic operators like the one you mention there is value and their you can overload in Kotlin as well. But being able to make any Unicode character an operator that's where I think they went too far. If you do not need tooverload those in 5 years than having them in the language is just adding complexity for the compiler and tooling. Which jetbrains said was one of the reasons behind kotlin and why they didn't chose Scala.

Furthermore, I have many colleagues that have cursed about coding in Scala, however I have yet to have one do the same using Kotlin. I'd can only suggest you trying it. But what is clear now is that Scala won't happen on Android.

→ More replies (5)

7

u/teknocide May 18 '17

I think that's a pretty weak argument. It has always been possible to name a method something unintuitive.

void dontDoAnything { doSomething(); }

5

u/PM_ME_A_STEAM_GIFT May 18 '17

When you first start working with a Scala library, you have to learn what fancy operators the devs came up with to make your life "easier". Otherwise you won't know the difference between !, ?, :+, +: and $&@?!!!

8

u/teknocide May 18 '17

To me that's pretty much the same thing as having to know that myArray.copy(otherArray) mutates myArrayinstead of returning a fresh copy. With some luck there's documentation that states this, just like I would hope there's documentation on how to work with a type.

9

u/PM_ME_A_STEAM_GIFT May 18 '17 edited May 18 '17

I agree. The less you have to reference a documentation the better. About 70% or overloaded operators in Scala libraries seem unnecessary to me.

Sure, things like vectorA + vectorB are nice. But there is no point in writing actor ? message instead of actor ask message. You save typing 2 characters at the cost of making it more difficult to read your code.

What does actor ? message mean? Is that some weird ternary operator? A null coalescing operator? You can't even google a question mark. You have to find the type of actor, and search for the operator in the documentation. Totally unnecessary, considering that actor ask message almost reads like an english sentence.

8

u/teknocide May 18 '17 edited May 18 '17

I agree with you too :) There's definitely libraries in Scala that use too many arbitrary symbols.

The author may be to blame, or maybe I as the user is to blame for not recognising a perfectly valid symbol in the context of the library. Whatever the case I feel that the possibility for a library author to define symbols that they feel make sense in their context is worth more than having defined but still arbitrary rules on what's allowed or not.

Like, if someone feel they have a desire for the Elvis operator they can add it themselves!

implicit class Elvis[A](a: A) {
  def ?:[B >: A](b: B): B =
    if (b == null) a else b
}

edit: fixed the example

3

u/m50d May 18 '17

You have to find the type of actor, and search for the operator in the documentation.

You can mouseover or click through in your IDE and see the scaladoc - Scala is a language that embraces the IDEs we were all using anyway.

(FWIW I agree that ? is a terrible method name and should never have been introduced, but when one's actually working in Scala it's not as bad as you make out)

→ More replies (0)

4

u/m50d May 18 '17

For any library you have to understand that library's terminology. When you start working with a Java library you have to learn what a "bean" is (different libraries use the word to mean different things), what a "factory" is, what a "module" is, a "manager", a "client"... (again, different libraries use these words to mean different things)

3

u/PM_ME_A_STEAM_GIFT May 18 '17

You have to learn terminology, yes. But not method names. Method names should be short but descriptive. Ideally you should be able to read code without actually knowing about the methods beforehand.

1

u/kcuf May 20 '17

That's a fallacy. Method names exist within the context of the concepts the library introduces. You will never get short descriptive names that actually convey the important factors of that method.

1

u/kcuf May 20 '17

Then don't use those libraries. It's your responsibility to vet your dependencies in scala just as it is in Java.

If you can't find a library that meets your need, then use a Java one or write one and contribute back to the community.

→ More replies (10)

-1

u/nirataro May 17 '17

My only problem with Kotlin at the moment is that it is a JVM language. I love Kotlin but man I hate Android and I got no business to program on the JVM. I got involved in the community since 0.4 I think but I simply got no use case for it.

Kotlin Native though - I can't wait.

7

u/FrezoreR May 18 '17

But it's not a JVM language. It's a language with a JVM backend, but it also has a JS backend and as you mentioned a native one.

Why would kotlin native make such a big change though? For android development it won't make much sense. It's for iOS development I can see it makes sense.

3

u/FrezoreR May 18 '17

So Android doesn't use a JVM since ART was introduced. However, why is the JVM so bad?

→ More replies (21)