Hello and welcome to another post in my blog about functional programming. In this space we review several advances and insights made possible by the functional programming paradigm as a relatively new way to solve computational problems.
In this occasion, I read "The promises of functional programming", by a scientific computer researcher named Konrad Hinsen.
In this paper, we can learn some core differences between the object-oriented style programming and the functional style-oriented programming. In general, we have spoken before about this differences throughly, which include:
- There are almost no variables
- It's power relies on pure functions.
- No for loops, everything is implemented through recursion.
- Parallelization and concurrency optimizations.
This main reasons are several that show that functional programming is essential, in my opinion, as a compliment to object - oriented languages, like Java. Let me explain each point, before trying to explain this.
Functional programming languages do not make use of almost any kind of variable. The reason this is like this, is because when you call a function, you can call another function with that result. In another words, you can send functions as parameters to another functions. Yet, there are some implementations in Clojure - and in any other functional languages - that do require variables. That's why Clojure has the option to implement variables such as: vars, agents, atoms and references. All of this can be modified dynamically through a series of operations for each type of variable. The reason why everything could be done without variables, leads me to point number 2.
The reason why everyone says that functional programming languages make use of no variables, is because (I think) they're looking at it from a mathematical point of view, rather than a "real world" problem. As I have said before, at the core if you want to use the full power of functional languages you have to rely on pure functions. A function is said to be pure when every time you give the same input, it produces the same output, and that output does not have any impact anywhere else in the program's "world". Take for example f(x) = 2 + x. That is a pure function because no matter what value you evaluate it to, it will always produce the same output, say for example f(2) is always going to be 4. As opposed to a pure function, an impure function is one that relies on something other that what is in it's scope, for example take the function f(x) = 2 + x + a. The result of this will variate depending on the current state of a. And now, the problem with this approach is that sometimes we do want or need to use variables, so this approach works as an optimization to object-oriented approaches, in which it is way much easier to use "real world objects" such as sockets to managing connections.
In general, I think that functional programming is really exciting, trust me, it is incredibly easy to write robust programs that have a lot of functionality. The code seems elegant, and I think that once you grasp the full power of the language, developing time could be better than object oriented one.
Please go ahead and read "The promises of functional programming" by Konrad Hinsen to get more insights on the topic!
See you soon,
- Diego.
Comments
Post a Comment