Peter Van Roy
(such as functional and object-oriented programming), since they already have a huge
literature.
Solving a programming problem requires choosing the right concepts. All but the
smallest toy problems require different sets of concepts for different parts. This is why
programming languages should support many paradigms. A programming paradigm is an
approach to programming a computer based on a mathematical theory or a coherent set of
principles. Each paradigm supports a set of concepts that makes it the best for a certain
kind of problem. For example, object-oriented programming is best for problems with a
large number of related data abstractions organized in a hierarchy. Logic programming
is best for transforming or navigating complex symbolic structures according to logical
rules. Discrete synchronous programming is best for reactive problems, i.e., problems
that consist of reactions to sequences of external events. Languages that support these
three paradigms are respectively Java, Prolog, and Esterel.
Popular mainstream languages such as Java or C++ support just one or two separate
paradigms. This is unfortunate, since different programming problems need different
programming concepts to solve them cleanly, and those one or two paradigms often do
not contain the right concepts. A language should ideally support many concepts in
a well-factored way, so that the programmer can choose the right concepts whenever
they are needed without being encumbered by the others. This style of programming
is sometimes called multiparadigm programming, implying that it is something exotic
and out of the ordinary. On the contrary, in our experience it is clear that it should be
the normal way of programming. Mainstream languages are far from supporting this.
Nevertheless, understanding the right concepts can help improve programming style even
in languages that do not directly support them, just as object-oriented programming is
possible in C with the right programmer attitude.
This chapter is partly based on the book [50], familiarly known as CTM, which gives
much more information on many of the paradigms and concepts presented here. But this
chapter goes further and presents ideas and paradigms not covered in CTM. The code
examples in this chapter are written in the Oz language, which is also used in CTM.
Oz has the advantage that it supports multiple paradigms well, so that we do not have
to introduce more than one notation. The examples should be fairly self-explanatory;
whenever anything out of the ordinary occurs we explain it in the text.
Contents of this chapter
Languages, paradigms, and concepts Section 2 explains what programming
paradigms are and gives a taxonomy of the main paradigms. If your experience is limited
to one or just a few programming languages or paradigms (e.g., object-oriented program-
ming in Java), then you will find a much broader viewpoint here. We also explain how we
organize the paradigms to show how they are related. We find that it is certainly not true
that there is one “best” paradigm, and a fortiori this is not object-oriented programming!
On the contrary, there are many useful paradigms. Each paradigm has its place: each
has problems for which it gives the best solution (simplest, easiest to reason about, or
most efficient). Since most programs have to solve more than one problem, it follows
that they are best written in different paradigms.
10