jueves, 3 de marzo de 2016

The promises of functional programming

Today I will talk about the article "The promises of functional programming" by Konrad Hinsen.

This blog's song will be "7 years" by "Lukas Graham", great song.

Enjoy.

The article talks about the differences between functional programming (as seen in Lisp, Mathemathica and other weird programming languages) and Imperative programming (as seen in C).

Lisp became a promise of better programming languages many years ago, however, that promise isn't still completely fulfilled, to anyone that has programmed in Lisp or any of its many dialects, it is very simple to see that Lisp has a completely different approach towards programming problems, and in many ways, a more powerful one.

I think I have said this many times, but there is always a tradeoff in programming languages, and Lips isn't the exception, it's killer feature is the same that makes it so hard, it is difficult to understand, no matter how many times Lisp gurus tell anything else, learning Lisp requires a lot of effort and thinking different, the main difference between Lisp and C is that in Lisp everything is made out of functions, pure functions (in C functions work more like methods or procedures).  So you have to think different to define a function, rather than a procedure. Hence why Lisp was considered a slow language many years ago, machines work internally using procedures, not functions, so the first thing that slowed Lisp's progress was how hard it was to translate Lisp code to machine language, sometimes, things get lost in translation.

However, as time passed by, hardware become more complex, right now parallelism is becoming the next big thing, and the main problem we have right now is that even if our machines have four or eight cores, most programs just use one or two, even games, which have always tried to push the hardware to its limits by using every obscure programming language they could be programmed (a couple of decades ago, a lot of games were still programmed in some sort of assembly language, to be more efficient, another great story is the engine behind Doom and Heretic games, programmed by the great Jogn Carmack, the engine wasn't purely 3D, instead, it displayed 2D textures and modified them using mathematical functions because computers those days weren't so great displaying 3D graphics, which made the game extremely fast and the objects would sometimes "bend"). I got a bit lost, returning to the point, even games nowadays use only 2 or at most 4 cores.

We still have many cores so we can run multiple processes at a time, but a single process almost never fully uses the computer, the main reason behind this is that programming parallel applications is a very hard thing to do, there are a lot of race conditions, data is often corrupted by other threads/cores.

Functional programming is a great promise to solve this problem because programs are interpreted as pure functions, not procedures, they don't use variables in a traditional way, hence being mostly thread safe, and I say mostly because there is still a lot of work to do regarding translating to thread safe, machine code. But any functional programmer can tell you that they have a lot less problems programming parallel applications than the guys who code in C.

In a couple of years, we will still use a lot of imperative programming, but it is certain that there will be a lot more functional programming as a common practice in programming.

Wololo.

No hay comentarios:

Publicar un comentario