• Post Reply Bookmark Topic Watch Topic
  • New Topic

Functional Programming in Android?  RSS feed

 
Pete Letkeman
Ranch Foreman
Posts: 851
25
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Currently the "stable" version of Android Studio does not support everything that is in Java 8 the next version 2.4 (beta) will.

From what I've gathered (and I could very well be wrong) functional programming using Java mainly uses the features introduced in Java 7 and Java 8 such as streams and Lambdas.

Given all of this, would it be advisable to start to do functional programming in Java?

I can see from this posting https://coderanch.com/t/685439/java/Complexity-program-search-word-based that which Pierre-Yves Saumont has posted for a solution is much smaller and possibly more concise.
I say possibly because I do not know my Lambdas or my streams too much yet.

A world of writing less code to get the same results sounds like a good idea to me.
 
Pierre-Yves Saumont
Author
Ranch Foreman
Posts: 156
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pete,

Functional programming with Java 6 or 7 is much more difficult, although possible. It is possible to do functional programming with any language. This dos not mean one should do it. I used to do functional programming in Java 6, but it was a real pain. You might better wait for next version, or you could use Kotlin. Kotlin is much more functional friendly than Java and has many other benefits. Plus it is now officially supported by Google as a language for Android development. The main drawback is that there is no book about functional programming in Kotlin. If you are interested, I suggest contacting Manning and ask them for a Functional Programming in Kotlin book. And if you know other programmers interested, tell them to do the same 
 
Tim Moores
Saloon Keeper
Posts: 3967
94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The stream API and lambdas are full baked into Android from version 7 (Nougat), which you likely won't be able to limit yourself to for quite some time (I have only recently dropped support for Android 4 for an app of mine, and even that was not an entirely easy decision.)

By way of https://github.com/evant/gradle-retrolambda, you can use lambdas on all Android versions. So you could, for example, write

instead of

which you may or may not see as a worthy improvement. I've recently started to use that, and have decided to do so across all apps I work on.

Support for the java.util.function (functional interfaces) and java.util.stream (streams) API can be had on pre-Android 7 versions via https://sourceforge.net/projects/streamsupport/. I haven't tried that one myself.
 
Pete Letkeman
Ranch Foreman
Posts: 851
25
Android Chrome IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pierre-Yves Saumont wrote:Kotlin is much more functional friendly than Java and has many other benefits. Plus it is now officially supported by Google as a language for Android development.

Yes, that is what I'm going to do. I just thought I'd get some thoughts on this before I go down that road.

Tim Moores wrote:By way of https://github.com/evant/gradle-retrolambda, you can use lambdas on all Android versions. So you could, for example, write
...
Support for the java.util.function (functional interfaces) and java.util.stream (streams) API can be had on pre-Android 7 versions via https://sourceforge.net/projects/streamsupport/.

Thanks the for tips Tim.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!