This blog talks about the advantages of
functional programming. It helps the reader to understand what makes Clojure
language a powerful tool for parallelizing and dealing with concurrency.
To
use functional programming, we must compute functions, a mapping from input
values to output values, the function returns the same output when given the
same input and it´s only task is to return a value without side effects. As a
function, does not change anything in memory, variables are not needed, this
makes a great advantage because unlike traditional programming, you can trace
the function call chain to know where a value came from.
Functional programming uses abstraction, so
we can use a higher-order function as a result. This kind of functions uses
another function as a parameter and return a function as a result, with these
functions is easier to implement patterns that occur repeatedly inside an
algorithm.
Clojure is a Lisp derivation, it is a
functional in terms that it deals with the mathematical definition of a
function, every new function defined by the opening of a parenthesis returns
either a value, or another function.
Clojure uses recursion, and lazy sequences
instead of typical loops to manage concurrency. It also talks about that we must
make use of this kind of functional languages to take advantage from non-stopping
technological world.
Concurrency and parallelism are gaining importance
because single threaded performance is not improving as it used to, and
computer hardware is getting more powerful and to take advantage of this power,
concurrency and parallelism are to be used.
Concurrency is difficult to use because
several threads need to coordinate to not use data at the same time to avoid
errors in the result, this is currently solved by locks, semaphores, etc.
Functional programming offers regarding
concurrency and parallelism, there is a long way until parallel programming is possible
as it is imagined
No hay comentarios.:
Publicar un comentario