Data and the operations upon it are tightly
Data is only loosely coupled to functions.
Objects hide their implementation of operations
from other objects via their interfaces.
Functions hide their implementation, and the
language’s abstractions speak to functions and
the way they are combined or expressed.
The central mode for abstraction is the data
itself, thus the value of a term isn’t always
predetermined by the input (stateful approach).
The central mode for abstraction is the function,
not the data structure, thus the value of a term
is always predetermined by the input (
The central activity is composing new objects
and extending existing objects by adding new
methods to them.
The central activity is writing new functions.
ing the same data at the same time,
one processor may alter the input to
the other; if that happens in the wrong
order or at the wrong time, the results
could be incorrect. In functional programming, each processor would only
need to read the original data, which
would remain unaltered.
The fact that the computational
state of the system does not change
makes it easier to understand what
exactly a program is doing, says An-
toy. “It’s more difficult to reason about
computation in which there is a state,”
he says. Object-oriented imperative
languages such as C, Java, or Python
change their state as they run. “If you
have a computation in which you have
variables that can change over time,
when you reason about this you don’t
know what the value of the variable is at
that time, so it’s like shooting a moving
target. You want to reason about some-
thing and things keep changing.”
Because the state does not change,
functional languages are attractive for
programs that require a high level of
security, such as those used by finan-
cial institutions, where functional pro-
grams are becoming increasingly popu-
lar, says Philip Wadler, a professor of
theoretical computer science at the Uni-
versity of Edinburgh in the U.K. and one
of the creators of Haskell. “You need to
AS COMPUTERS BECOME more powerful and the programs that run them grow more complex, pro- grammers are increasingly
trying to make their lives easier by turning to an idea that dates to the early days
of computer languages, an approach
called functional programming.
“Functional programming’s on
a long steady burn, starting 30 or 40
years ago,” says Simon Peyton Jones,
a researcher at Microsoft Research in
Cambridge, U.K., where he focuses on
the functional language Haskell.
Programming languages break down
into broad categories. There are imperative languages, which say, “do this, then
do that,” specifying a series of steps to
accomplish a task. Functional languages, on the other hand, rely on functions,
which are mathematical operations.
“A function is just basically a piece
of an algorithm,” says Iavor Diatchki, a
senior research and development engineer at Galois, a software company in
Portland, OR. “It’s something that you
can give some inputs and it computes
some outputs.” For instance, “plus” is
a basic function; it says to take two integers and combine them to produce one
integer as a result.
Functional languages operate at a
higher level of abstraction, automating
a lot of the details that underlie a particular operation. That makes it easier
to write programs quickly. Years ago,
when computers were slower, that ease
came with a cost, Diatchki says; the program’s default steps were not always the
most efficient, and a programmer could
make it run better by taking the time
to tweak the details. That has changed.
“Computers are a lot faster, so things
like that don’t matter all that much,”
says Diatchki, who argues that mak-
ing better use of a programmer’s time
has become more important. “Also, the
kind of software we write tends to be a
lot more complicated, so some of these
small performance issues are not nearly
as important. What’s important is that
you manage to put all the pieces togeth-
er and get the program to work.”
Higher-level languages are more
productive, says Sergio Antoy, Textron-
ics Professor of computer science at
Oregon’s Portland State University, in
the sense that they require fewer lines
of code. A program written in machine
language, for instance, might require
100 pages of code covering every little
detail, whereas the same program
might take only 50 pages in C and 25 in
Java, as the level of abstraction increas-
es. In a functional language, Antoy says,
the same task might be accomplished
in only 15 pages.
Additionally, the less a developer
writes, the less opportunity he has to in-
clude something that causes a problem.
“As you remove details, you remove the
potential for error,” Antoy says. Higher-
level languages also lead to programs
that are easier to modify if the underly-
ing machine architecture changes.
Another important aspect of func-
tional programming is that functions
do not change the data with which
they work. Having immutable data
makes it easier to do parallel process-
ing. If two processors are manipulat-
Using Functions for
Functional programming languages automate
many of the details underlying specific operations.
Technology | DOI: 10.1145/3193776 Neil Savage