Skip to main content

The promises of functional programming, by Konrad Hinsen

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:

  1. There are almost no variables
  2.  It's power relies on pure functions.
  3. No for loops, everything is implemented through recursion.
  4. 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

Popular posts from this blog

Beating the Averages

This is a review of the reading Beating the Averages by Paul Graham,  which you can read here .   Our resistance as humans to learn new things is expressed in a function named the learning curve. The learning curve represents in a mathematical form of how we learn through time. It accomplishes this by taking into the equation experience with a particular subject or topic and placing it vs learning. In particular, I like this funciton because it represents one of the author's main points: why we tend to prefer what we already know. What this function represents is that we tend to have some resistance to new knowledge. We may apply this resistance through contradicting knowledge that we might already have, namely, experience in a certain field, maybe because it a new paradigm to see things, very different from what we are used to. As we grow older, it becomes harder and harder to change the way we see things. The Paul Graham, the author, expresses this himself, he say...

Revenge of the nerds, by Paul Graham.

So, once again we go to Paul Graham and his absolute amazing opinions on lisp. He understands the difficulty in changing the industry, but faces this with a good sense of humor and courage. You can check out his blog entry here . Taking it to the next level So the story goes like this. Michael Phelps went out there to change the world of an olympic sport. And did. Only he and his coaches know what he is doing differently but definitely, he is. Michael Phelps is such a good example because before Phelps, it was very rare to think of a swimmer that could do all the strokes in a competition, from crawl from breast stroke to his olympic record breaking butterfly stroke. In a sense, Phelps is like lisp. Phelps came to the 2004 Athens olympic games as a kid, he was only 19 years old, but everyone knew he had the chance to break the olympic record for 7 gold medals in the same event. He went on it and won 8 of them. So... what is he doing differently than any other swimmer? How long does...

Dick Gabriel on Lisp

So this post is going to be about the high and downs of LISP. You can check out the amazing talk that Dick Gabriel gave on LISP history, it's capabilities and what he calls " The winter of LISP" . Go ahead and check it out here . I thinks it's a little bit sad to think about how great LISP is and all the capabilities that it has, and just see it as "God". We can not bring God down to earth so easily. Some of us, may go ahead and try and check it out, and then just think... wow... how the hell didn't I thought about this that way before? It really hasn't been that long since I started learning what LISP is about. Today is about the third week I believe (maybe fourth, I don't know) since I started. And I already feel that this language should be the language of the future. After listening to this guru of LISP research, one of the biggest name in the community, it just made me feel a little dull. Knowing that everything is so cool on LISP, how ...