[comp.graphics] Functional and Object Oriented Languages compared

edwin@cwi.nl (Edwin Blake) (06/21/89)

I am interested in abstractions for computer graphics, particularly
dynamic graphics such as animation, interactive systems and CAD.  It
seems to me that the leading contenders for an abstraction for computer
graphics are the declarative languages and object oriented (o-o)
languages.  I am reasonably familiar with o-o abstraction, less so with
the functional/logic one, but lets have some reactions!

Functional programming has been used for computer graphics [Arya, 1986,
1989; Henderson, 1982; Salmon & Slater 1987].  (There are so many
references for o-o graphics that I will not be giving any!?! -- they can
be had on request.  I would be interested in further references to PURE
functional graphics.)

From the point of view of the graphics programmer an important benefit
of declarative languages is that they shift the burden of deciding how a
thing has to be done from the programmer to the architecture.
Constraint based o-o programming also has a declarative flavour in this
sense.  Both FUNCTIONAL and LOGIC languages are declarative.  The need
for declarative programming in animation and interaction has long been
recognized [see e.g. Borning & Duisberg, 1986; Zeltzer, 1985]

Pure declarative languages employ no side-effects whatsoever and
assignment of values to variables is impossible.  In object oriented
terms one could say that data is always completely encapsulated.  In
fact, declarative languages lack a notion of `state of computation'.
This is in direct opposition to the idea of self contained objects which
persist over time while their internal configuration changes.  This
seems to lead to CONCEPTUAL difficulties when we consider interactive
graphics and computer animation.

Functional programming derives its power from giving functions first
class status.  Data structures are defined by means of constructor
functions which make abstract data objects.  Access is only via the
operations defined on the data objects.  As in o-o functional
programming also emphasizes polymorphism and concurrency.

Pure functional programs are static objects.  The meaning of an
expression does not change as computation proceeds.  But real, physical,
objects persist while their configurations and attributes change over
time.  Animation, as the mimicking of three-dimensional physical
objects, depends on a notion of STATE.  This meshes rather well with the
concept of actors and objects in object oriented programming.  In
functional graphics the emphasis is shifted to dealing with a sequence
of DIFFERENT objects related by a sequence of transformations.  This
model of computation is found in key frame animation, which is mainly
used for two-dimensional pictures.

Slater also discusses the fact that difficulties arise when using
functional languages for programming interaction and when using
attributes [Salmon & Slater, 1987, pp. 290-291]. 

This does not prevent functional programming from being used in practice
in time dependent situations.  Generally it is possible to ABSTRACT AWAY
the notion of time, and replace it with some idea of sequences over
infinite lists.  Recent developments in lazy functional evaluation make
such infinite lists tractable.

To discover the relation between the figures in the list one refers to
the functions which constructed them.  BUT the conceptual advantages of
functional programs remain limited precisely because such programs
describe a dynamically changing world as a (conceptually) frozen system
of infinite sequences.

The extent to which a (possibly impure) functional approach can be
elaborated for three-dimensional animation needs further investigation.
On the other hand, object oriented animation already seems well suited
to modelling changing objects executing concurrently.


References.
===========
Arya, K.  (1986)  Computer Graphics Forum  vol 5, 4  297-311
"A functional approach to animation."

Borning, A.H. & Duisberg, R.A.  (1986)  ACM Trans.Graphics  vol 5, 4  345-374
"Constraint-based tools for building user interfaces."

Henderson, P.  (1982)  Symposium on Lisp & Functional Programming.  9pp
"Functional geometry."

Salmon, R. & Slater, M.  (1987) Computer Graphics: Systems & Concepts.
Addison-Wesley, Wokingham, England.

Zeltzer, D.  (1985)  The Visual Computer  vol 1 249-259
"Towards an integrated view of 3-D computer animation."

-- 
---------------
Edwin Blake, edwin@cwi.nl   	Phone: +31 20 5924009
Centre for Mathematics and Computer Science (CWI)
Department of Interactive Systems,
Kruislaan 413,  1098 SJ  Amsterdam,  The Netherlands