OpenSource For You

Lisp’s Functional Programmin­g advantage

-

Functional Programmin­g is the art of writing programs that work by returning values, instead of modifying things. Functional Programmin­g also enables you to create fabulously powerful and very efficient abstract programs – it is a mathematic­al approach to programmin­g. In math, for at least the last 400 years, functions have played a very central role. Functions express the connection between parameters (the ‘input’) and the result (the ‘output’) of certain processes. In each computatio­n, the result depends, in a certain way, on the parameters. Therefore, a function is a good way of specifying a computatio­n. This is the basis of the functional programmin­g style. A ‘program’ consists of the definition of one or more functions. With the ‘execution’ of a program, the function is provided with parameters, and the result must be calculated. Writing code in a functional style guarantees that a function does only one thing (returns a value), and is dependent on one thing (the parameters passed to it). This equips you to control side effects.

However, some side effects are almost always necessary for a program to actually do something. This means that you can’t write a useful program that has the entirety of its code written in the functional style. In Article 8, where we talked about CLOS, I pointed out James Hague’s assessment of functional programmin­g, where he argues that, “100 per cent pure functional programmin­g doesn’t work. Even 98 per cent pure functional programmin­g doesn’t work. But if the slider between functional purity and 1980s BASICstyle imperative messiness is kicked down a few notches—say, to 85 per cent—then it really does work. You get all the advantages of functional programmin­g, but without the extreme mental effort and unmaintain­ability that increases as you get closer and closer to perfectly pure.”

Newspapers in English

Newspapers from India