This week's book giveaways are in the Angular and TypeScript and Web Services forums.
We're giving away four copies each of Programming with Types and The Design of Web APIs and have the authors on-line!
See this thread and this one for details.
Win a copy of Programming with Types this week in the Angular and TypeScript forum
or The Design of Web APIs in the Web Services 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
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

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: 160
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: 5978
154
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.
 
The fastest and most reliable components of any system are those that are not there. Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!