Will functional programming have a Renaissance?

In the 1980s and 1990s the war between declarative programming and imperative programming was eventually won by object-oriented programming. Declarative programming was represented by logic programming with Prolog, and by functional programming with languages like Scheme, Erlang and Haskell. Imperative programming was represented by the heirs of structured programming, all based on abstract data types, of which the object oriented languages such as C++ and Smalltalk were the favoured languages of the time. And then came Java and that was it—imperative, and object-oriented in particular, won. Or did it?

Ever since the hegemony of imperative programming was established, the mainstream programming languages have been moving more and more towards declarative expression. A trivial, but very indicative Java example, looping through the elements of a list is traditionally written in a way directly inherited from C and C++:

iterates over each element of the list, represented as an array, calling a function. However, most people are now of the opinion that this is a very low-level form of expression that is useful in very few situations. Instead, the modern way of expressing iteration is exemplified by the Java statement:

for ( SomeType s : list ) { doSomethingWith ( s ) ; }

Other imperative languages are going down this road. For example in Python:

for item in list : doSomethingWith ( item )

and in C++:

std::for_each ( list.begin ( ) , list.end ( ) , doSomethingWith ) ;

The programmer no longer has to worry about how to access the elements of the data structure, nor how to keep proper control of the iteration variable: the details of how to do iteration are hidden away in a declarative expression. This more declarative mode of expression allows the programmer to assume that between them the compiler and runtime system will get it right. So the evolution of abstraction in programming appears to show that declarative rather than imperative expression is the higher level abstraction.

So, did functional programming have it right in the first place? Are the imperative languages slowly transforming into functional languages? Well, yes—and no! The evolution of C++, Java and Python shows that declarative expression is to be preferred over imperative expression in many situations. So why did the declarative languages fail to win the hearts and minds of programmers and their managers in the 1980s and 1990s?

Part of the reason is that functional languages were seen as academic and imperative languages were for real programmers. There was also a very large amount of imperative code and expertise around and nowhere near the same amount of functional programming expertise. Having said that, Erlang grabbed a central place in the development of telephony switchgear, and Java seized a central place in the world of Web services. So it is possible for new programming languages to burst onto the scene. Usually, though, it comes when there is a new class of application to be constructed, or a radical new requirement that existing languages cannot satisfy—for example trading room systems, where statically compiled and linked systems were not suitable, so Smalltalk and then Java filled the gap.

Is there a way functional programming can move centre stage? Will Haskell become a dominant language? I suggest not. Two main reasons: a) recursion is a fine way of expressing recursive functions and recurrence relations, but it is a very poor way of expressing iteration; and b) the currently dominant languages are evolving to incorporate all the most expressive aspects of functional languages. Declarative modes of expression may be good when appropriate, but being able to write an explicitly imperative statement when needed is the flexibility that functional languages do not have.

So is the door open to languages such as Scala and OCaml which combine declarative and imperative? Possibly. What is more likely is that Java will evolve to encompass the features that Scala and OCaml have that are useful, which it does not already contain.

Can functional languages have a renaissance? Yes. Learning about functional programming is a very good way of improving your programming in imperative languages. The consequence is that every C, C++, Java, Groovy, Python, Fortran, etc. programmer should be studying languages such as Haskell, OCaml, Scala and Erlang. Not because those languages will be used directly in development, but because the way of expressing things in functional languages leads to excellent idioms in imperative languages. As the Psychology of Programming community has known for many years, an important measure of programming expertise is the number of different programming paradigms a developer is competent with. The most important paradigms are procedural (exemplified by C), object-oriented (exemplified by C++ and Java), and functional (exemplified by Haskell and Erlang).

For Java programmers, Scala is interesting exactly because it merges functional and imperative programming in an integrated way. It will probably not take over from Java, but it has an important place nonetheless, if only as a useful training vehicle.

And there was never a golden age of functional programming, so there can't be a Renaissance.

Peace -stephan

Posted: 1st March 2008 | By Pateris :

I think that functional programming does has one significant advantage over procedural programming. Zero side-effects makes multi-core programming easier because there is less risk of accessing "common" memory and the problem of mutexes, locks, etc. goes away (mostly)

Posted: 2nd March 2008 | By James Bowery :

To first order, there is no point in pursuing any programming paradigm other than relational because all other programming paradigms are more parsimoniously described as relations, including SQL-type programming, than any other programming paradigm.

Once you accept that, then you can prioritize your work properly -- and there is a lot of work to do here.

The messages above were all contributed by IT-Director.com readers. Whilst we take care to remove any posts deemed inappropriate, we can take no responsibility for these comments. If you would like a comment removed please contact our editorial team.

We automatically stop accepting comments 180 days after a post is published. If you would like to know more about this subject, please contact us and we'll try to help.