Even as some argue exactly what it is, functional programming keeps attracting developers. And three of the most popular functional languages -- Clojure, F#, and Scala -- are on tap for improvements.
Functional programming has a core appeal for some developers, says Scala founder Martin Odersky: "The programmers in that segment like functional programming because it makes code clearer, better structured, and it prevents many classes of errors." But some argue that functional programming leads to less-efficient software.
Functional programming also requires thinking about programming in a new way, says David Stephens, Microsoft's program manager for .Net and a spokesman for F#. Abstractions can be an issue: "When you make code more abstract, when you're moving further away from manipulating bits and explicitly going through loops, it can take more time to understand these abstractions."
What is a functional language, exactly?
In its most basic terms, functional programming is about treating computation as mathematical functions. In addition to languages billed as functional from the start, the likes of Java and C# have become more functional by adding support for lambda expressions.
But a precise definition of functional programming can be hard to pin down. The Clojurefun blog cites several definitions it believes are incorrect, including defining functional programming as enabling a functional style with higher-order functions or a language supporting lambdas. It says the correct definition is a language emphasizing functions and immutable data.
But the Clojure blog's preferred definition isn't necessarily correct, others say. "The author picks one, which incidentally fits Clojure best -- no wonder, this is a Clojure blog," Scala's Odersky says. "I have an interpretation that is close to his, but not the same."
A function, Odersky says, is a piece of code that maps inputs to outputs and has no other effects beyond that. "It's the mathematical definition of function we are using here. Sometimes these functions are called 'pure,' to distinguish them from, say, functions in C." A functional language focuses on programming with pure functions, making it easy and powerful to do so, says Odersky, who founded Typesafe, the provider of the Typesafe JVM application development platform.
Functional programming can be combined with other paradigms, he notes. "For instance, functional goes really well with object-oriented. Scala is a functional language in that sense. I agree that just having lambdas does not make a language functional; it is necessary but not sufficient."
Clojure developer Rich Hickey, who's also CTO at systems developer Cognitect, concurs with a main contention of the Clojure blog. "The article correctly points out that first-class or higher-order functions are not what functional programming is all about. Functional programming is about making programming more like mathematics," he says. That says, there still remains a spectrum of definitions for functional programming, Hickey says.
Microsoft's Stephens sees functional capabilities extending beyond languages alone. "The most popular functional programming language in the world is Excel," he says. A simple Excel worksheet might have a column with a bunch of values in it, such as A1 X 2. "That's a pure function on A1, and A1 doesn't change, so you're computing values from that existing data."
Microsoft's Language-Integrated Query (Linq) technology also provides for functional programming, he says. "Almost every programming language now is adopting features from functional languages."
Stephens cites immutable data as critical to functional programming. Concurrency -- programs with multiple threads operating on data simultaneously -- also benefits from immutable data, he notes. "We call [F#] a functional-first language because it comes from a heritage of other languages." It also supports object-oriented programming and operates with C# and Visual Basic, he says.
Clojure's Hickey sees adoption of functional languages as a response to the increasing pressure facing developers, who have to take on bigger problems these days. "To do so, they must reduce the incidental complexity of their programs. It is now widely recognized that pervasive state and side effects are a primary source of complexity and bugs in programs," Hickey says. "While it is possible to reduce the amount of state in programs written in nonfunctional languages, it is dramatically easier and faster to do so in a language that makes functional programming idiomatic and the default."
What's next for the three top functional languages
The 13-year-old Scala is a primary language in data science, says Scala founder Odersky. Supported on the JVM, it has an estimated 400,000 to 500,000 users. Plans in the short term call for it to be optimized for Java 8, in which bytecode instructions from the latest standard Java upgrade would enable Scala to generate more efficient code.
The nine-year-old Clojure, also based on the JVM, has been used in finance, retail, software, and entertainment, Hickey says. "It's been applied in diverse application areas such as transaction processing and analysis, big data, network operations, predictive analytics, search, security, and consumer offerings."
The 11-year-old F# was founded by Microsoft Research by Don Syme and is overseen by the F# Foundation. It is used in a wide range of applications and runs on Linux, OS X, Android, iOS, Windows, and browsers. "What we're working on now is the make it work with .Net Core," an open source, cross-platform modular version of the .Net Framework, Stephens says. String interpolation, making it easier to write strings, is on the drawing board.
This story, "Functional languages: What they are, and where they're going" was originally published by InfoWorld.