News for hackers. Stuff that matters.
Re:Kotlin is the hero Android needs by moondowner on Friday May 19, 2017 @07:42AM (#14374637)
"Remember filtering lists with for loops? Thanks to the functional approach to collections, we can also reduce all the complex, multiline instructions to only one line of code."

Erm, same can be done in Java with the Java 8 stream API.

I like Kotlin and use it with Spring, but articles like this where programming languages are not compared properly make me cringe.

Re:Kotlin is the hero Android needs by StevePerkins on Friday May 19, 2017 @08:03AM (#14374770)
Even after 10,000 armchair lawyer discussions about the Google-Oracle lawsuit, I feel like 99% of developers still do not grok that Android's "Java" isn't really Java.

They wrote their own implementation of an earlier version, and at this point will probably never update its API to fully match Java 8 or beyond. Android devs who want advancements will have to add "shims", like retrolambda or (quite frankly) Kotlin.

Re:Kotlin is the hero Android needs by pjmlp on Friday May 19, 2017 @09:32AM (#14375414)
Aka language fork.
Re:Kotlin is the hero Android needs by norswap on Friday May 19, 2017 @08:01AM (#14374757)
True, but the stream API isn't very friendly. You have to get a stream (.stream()), filter, then collect in a collection (.collect(..)) for which you need to find a suitable collector (the stdlib supplies some for lists and maps, but you have to find where they are defined).

These are small things, and easily corrected with a bit of know-how and/or utility methods. But I think it has had a huge impact on the (non-)adoption of streams.

Another obvious API gap: going from an iterator or iterable to a stream requires much more ceremony than it should.

Re:Kotlin is the hero Android needs by vbezhenar on Friday May 19, 2017 @10:22AM (#14375889)
Actually I'm not sure if Kotlin's code is that performant. It'll create new ArrayList on each step just to discard it after. It won't matter for tiny lists, but even for moderate lists it does matter. If you want to iterate without creating new arrays on each step, you'll need to use Sequence. And now there's another problem: Sequence doesn't know its lengths. So when you'll collect computation result, you can't just allocate exact memory, you'll need to allocate some memory, then grow it, and so on. Java streams are lazy and they try hard to know expected output size, so they are better in some aspects.

That said, Sequence have very simple implementations while Java Streams are hairy monsters under the hood and you can use Java Streams from Kotlin without problems, if you're targeting JDK8.

Re:Kotlin is the hero Android needs by on_and_off on Friday May 19, 2017 @07:57AM (#14374734)
You don't have access to this API in Android.

Except maybe if you minAPI is something ludicrously high like 25, but that's not going to be the case for almost all apps in the coming year. Kotlin is useable right now.

Re:Kotlin is the hero Android needs by EwanToo on Friday May 19, 2017 @07:57AM (#14374731)
The last time I looked, Java 8 wasn't available (and probably never will be?) available on Android, which is what this article is talking about.

Edit - http://www.infoworld.com/article/3180758/mobile-development/... it looks like Android is gaining Java 8 support now

Re:Kotlin is the hero Android needs by GrumpyBen on Friday May 19, 2017 @08:01AM (#14374759)
No, some Java 8 features are available (https://developer.android.com/studio/preview/features/java8-...) but streams are only available on Android Nougat
Re:Kotlin is the hero Android needs by jondwillis on Friday May 19, 2017 @11:46AM (#14376785)
Wow! One line of code that is 400 characters long and difficult to parse! I don't know anyone worth their salt who writes functionally that doesn't use line breaks liberally to make things readable. Functional programming has very little to do with terseness IMO.