Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Usage of Functional Programming  RSS feed

 
Divya Shiv
Ranch Hand
Posts: 64
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Venkat,

When to use Functional Programming? What are the advantages/benefits of the same over other languages in such scenarios ?
 
Venkat Subramaniam
Author
Ranch Hand
Posts: 109
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Divya,

There are some key reasons.

1. Declarative instead of imperative. We focus on what to do and let libraries figure out the details. This makes the code more expressive.

2. Favoring immutability. The more mutability (especially shared mutability) we have, the more bugs tend to creep in. We can reduce bugs by favoring immutability.

3. State transformation instead of state mutation. This leads to more of a function composition and state transformation. The code becomes more expressive and it tends to resemble more
closely to the problem statement.

4. Efficiency through lazy evaluation. Because we are passing higher order functions, we can postpone evaluation of certain parts to just in time of need. This can leads to greater efficiency in code.

The collective benefit is more expressive, more concise, less error prone, easier to understand (once we get a hang of the style), and easier to maintain code.

Also, when we combine composition, immutability, and laziness with things like parallel streams, we can create highly efficient code with much less effort and chances of error.

Hope this gives you a very high level view of the reasons.

Thanks

Venkat
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Many of these features make FP especially useful for large-scale and concurrent distributed processing, which is one of the reasons why some of the key tools for Big Data are based on these principles e.g. Hadoop MapReduce engine, Apache Spark (written in Scala), etc. Back in 2013, Dean Wampler (now with Scala company Typesafe) gave a persuasive talk on why Copious Data Is The Killer App For Functional Programming, and so far he seems to have been on the right track with that claim.
 
Divya Shiv
Ranch Hand
Posts: 64
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Venkat.
 
Divya Shiv
Ranch Hand
Posts: 64
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chris.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!