Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What functional programming buzz is about ?  RSS feed

 
meenakshi sundar
Ranch Hand
Posts: 152
1
Python Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Author,

  Coming from Java and other languages, my prior experience hurt me more than anything. I had to forget *everything* that I knew in order to make
  Gains in this new world of functional programming. 

A whole lot of ways to write simpler, cleaner, faster code. I think that's the most important thing that matters when reading a new programming book.
There are a lot of concepts and idioms that people need to get used to and understand that is  especially true with new  programming paradigms such as
Functional programming but the really important stuff is being able to apply it in a practical setting.

What would you say to that?

 
Pierre-Yves Saumont
Author
Ranch Hand
Posts: 103
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would mostly agree. To make the most of a new language with a different paradigm, you have to think differently. Imperative programmers see programs as a series of instructions that change the state of some components. There is a starting state, and there is an end state, which hopefully is the result we expect. When we get to this state, the initial state, as well as all intermediate states, are lost. Things have been mutated.

Functional programming is different. A functional program is a system of expressions that may be replaced with their value. This process does not mutate anything. Adding 2 and 5 does not mean any mutation in functional programming. In imperative programming, it could be seen (and implemented) as removing 1 to one of the values and adding 1 to the other until the first one is equal to 0. When this state is reached, the second value is the result. Both original values have been destroyed. In functional programming, 2 + 3 does not "make" 5 as the result of a process. It is simply equivalent to 5, so it may be replaced with 5.

In the same way, adding a value to a list does not modify the list, but produces a new list with the value added. The original list is not modified. One may think that this is less efficient, since it implies duplicating a great quantity of data, but this is not true because data is shared. In fact, such a list may be much more efficient than a Java list for head access (access in first position). It is also far most efficient for element removal. It is less efficient of indexed access, but other data structures are available for this kind of use.

Another important feature of FP is abstraction. In FP, you generally don't repeat again an again control structures like if..else, switch..case of loops. They are abstracted into functions. It may seem weird to write programs without ever changing the value of a variable nor using any control structure. It is so weird at start that one should better take it as a brain puzzle. It's only when the concept is mastered that the full benefits appear.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!