Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Functional Programming in Android?

 
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • 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.
 
Author
Posts: 161
31
  • 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  
 
Saloon Keeper
Posts: 6600
161
Android Mac OS X Firefox Browser VI Editor Tomcat Server Safari
  • 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
Bartender
Posts: 1868
81
Android IntelliJ IDE MySQL Database Chrome Java
  • 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.
 
Yeah, but does being a ninja come with a dental plan? And what about this tiny ad?
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic