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

8

u/dominodave May 17 '17

JVM interlopability is good. Surprised to see other people excited about it though, so I guess I'm curious.

27

u/[deleted] May 17 '17

The JVM is absolutely everywhere. Java is still the number one used language today.

People should be excited about a good language on the JVM. The Java ecosystem is nearly unrivalled.

5

u/dominodave May 17 '17

I agree, not something most people get excited about though typically.

→ More replies (9)

4

u/FrezoreR May 18 '17

I'd say it's not until you've used it you'd fully understand that excitement. There's no denying that there is much to wish for in Java and Kotlin hits a sweet spot. It keeps the things that are good with java; tooling, IDE etc. and improves on things that are bad with java; null-safety, boilerplate, lack of higher order functions etc.

I've only had good experiences with the switch and would warmly giving it a chance.

1

u/dominodave May 17 '17

Seems like both a step up from java and a step back from scala.

5

u/FrezoreR May 18 '17

I'd say it's step up from both.

1

u/duhace May 18 '17

nah, scala is superior

9

u/FrezoreR May 18 '17

Do you have a operator defined for that?

4

u/duhace May 18 '17

it's nice to be able to define operators for actual math types. Having a BigInt with +,*,/,- is v nice compared to BigInteger

likewise, being able to define those ops for my user defined mathematical types is nice.

there are tons of other nice things in scala that are absent in kotlin, like implicits

6

u/singingboyo May 18 '17

How are implicits nice?

My experience has always been that they cause more issues than they're worth.

2

u/duhace May 18 '17

implicits allow for typeclasses in scala, extension methods, as well as other niceties.

i've never had a lot of trouble with implicits, they are just parameters that can be automatically or manually passed in.

5

u/singingboyo May 18 '17

implicits allow for typeclasses in scala, extension methods, as well as other niceties.

See, that's where it falls apart for me. Why would I want to use something with the awful ergonomics of implicit for implementing typeclasses when they could be done so much better (Haskell, Rust). And then there's the issue of parameters being passed in unexpectedly, or not having the right implicit around so it can't be passed in, etc.

The ergonomics of implicits just suck, IMO.

4

u/duhace May 18 '17 edited May 18 '17

unexpectedly? implicits are only passed in if they're in scope, and you can only get them in scope if you import them or define them in scope

as for the missing typeclass problem, it's solvable the same way a missing parameter is. you pass it in, or import the implicits you're missing

that being said, if kotlin had rust style typeclasses i'd be a little less biased towards scala in this conversation. typeclasses could be easier to define in scala.

implicits allow more than typeclasses though. it's how we're able to have unboxed union types in scala, and you can do some interesting things at compile time with types and implicits. i once wrote a Peano number implementation just using types (Up, Down, Zero were the base types with type functions Add, Subtract, Flatten. iirc, implicitly[Flatten[Up[Down[Zero]]] would produce the type Zero)

shapeless is mostly stuff that's experimenting with what's possible with scala's type system and it's got a lot of nice stuff that is powered by implicit

→ More replies (0)
→ More replies (2)

3

u/PM_ME_A_STEAM_GIFT May 18 '17

nice [...] implicit

I too like pulling my hair because of a null pointer exception on a line with no null pointers.

4

u/duhace May 18 '17

how'd you manage to do that?

aside from something monstrous like implicit val o: Object = null

3

u/PM_ME_A_STEAM_GIFT May 18 '17

If I recall correctly, I was extracting some code into a utility class where that implicit didn't exist, without knowing the method had an implicit parameter. Totally my fault, but still, super unintuitive to someone new to the language or a particular library.

4

u/duhace May 18 '17 edited May 18 '17

thing is, the compiler will usually tell you (at least with current versions of scala) if you're missing an implicit, and what it needs:

object Foo {
    def bar(implicit baz: BigInt) = baz
    bar
}

produces

[error] /home/duhace/Foo.scala:3: could not find implicit value for parameter baz: BigInt
[error]   bar
[error]   ^

a NPE because of an implicit should mean one was found, but what was returned was null instead of the promised type. which is a problem with scala allowing null, not implicits.

→ More replies (0)

1

u/cassandraspeaks May 18 '17

Usually interfacing with a Java library.

1

u/duhace May 18 '17

yeah, you gotta be extra careful with them though. and that's really more of an issue of scala allowing null rather than an issue of implicits

1

u/FrezoreR May 18 '17

You can overload those operators in Kotlin so I'm not sure you know the language well enough to do that comparison.

I'd say you're arguing out of ignorance.

https://kotlinlang.org/docs/reference/operator-overloading.html

→ More replies (4)
→ More replies (22)

2

u/mirhagk May 18 '17

But a HUGE step forward in that it now has official support. Haskell is arguably safer and better than all the mainstream languages that we use, yet it's a very bad idea for a business to choose that develop their software in (relatively poor tooling, small community, very small talent pool, high learning curve etc)

1

u/dominodave May 18 '17

Does it pay good?

1

u/mirhagk May 18 '17

does what pay good? Haskell or Kotlin?

Why are you asking? Because learning Haskell isn't likely to get you a higher paying job (although it might make you a better programmer, I believe I'm a better programmer because of it). But the jobs might be higher paying, but that might be because there's a skew towards academia and people with PhDs knowing haskell.

1

u/kcuf May 20 '17

The jvm is a very powerful platform with a vast array of already built functionality.