Help coderanch get a
new server
by contributing to the fundraiser
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Functional Programming Advantages

 
Ranch Hand
Posts: 171
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Would like to know about the how Functional Programming  has bought in the implementation changes in terms of structural code base. How it  improves the application implementation compared to the normal programming language ?
 
Author
Posts: 161
31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am not sure to understand what you mean exactly by "in terms of structural code base", but I'll try to answer anyway. The most important feature of functional programming is the separation between effects and functions. Effects are the part which interact with the outside world, (which can be the world outside the application, or just outside the component you are considering). The rest of the code is composed of functions, which have no other interaction than receiving values as argument and returning a result. In pure functional programming, there are no effects, which does not mean that the programs do nothing observable, but that they return something which will make the effect observable once activated. You can see it as if functional programs were returning a kind of imperative programs that can be executed. Less pure functional programs simply separate functions and effect inside the same program. To allow a maximal separation, it is necessary to push abstraction as far as possible. For example, all control structures are abstracted into functions, so you never manipulate these control structures, such as loops, conditional instructions, try..catch blocks, etc., Of course, this is not completely true if you use a non functional friendly language like Java: You have to define your own abstractions, so you must use them once.)

The benefit form separating functions from effects are that the functional parts are deterministic, so they can very easily be fully  tested, and even often proven correct. This makes programs more reliable. It also make them faster to develop, since testing time is much reduced as well as the number of implementation bugs due to the abstraction of control structures. It also makes programs more readable because abstractions are named and can be recognized. This is not obvious for beginners, because it is difficult to recognize what you don't already know. Functional programming implies a different way of thinking. One must not see programs as a control flow, with instruction changing the state of some components, but as series of expressions that may be combined to create new expressions, until obtaining a single function taking the input data as its argument and returning the output.
 
Sheriff
Posts: 17665
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
One of the hardest things for me in switching my mindset to functional programming was the higher levels of abstraction that you have to get used to.  

It's one thing to think of functions simply as methods. It's a whole 'nother thing to think of functions as values, things you can pass and return from other functions. There's an almost Inception-like (the Leo DiCaprio movie) feel to it when your brain tries to wrap itself around that idea. And then you have tail recursion and list handling and head and tail and all, these are things that I struggled with for quite a bit when I learned Scala and functional programming from a Coursera.org class given by Martin Odersky himself.

I consider myself lucky though because I had some previous experience with method pointers, function macros, and JavaScript functions, things that are similar in nature to higher-order functions, lambda expressions, and closures. I have to admit that when Odersky started talking about lambda calculus, my eyes started to glaze over and my brain automatically started to shut down in self-defense, for fear of exploding.
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally, I find it cryptic  (YMMV)
Maybe once I get accustomed to it, things may change. There are benefits, no doubt. But I find the code a bit harder to read. I was once equally afraid of Generics too.
 
Divya Shiv
Ranch Hand
Posts: 171
Netbeans IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Pierre, Junilu and Salvin for briefing on implementation of Functional Programming.

 
reply
    Bookmark Topic Watch Topic
  • New Topic