Subject: Re: a bit off topic, but can someone explain the different 'types' of programming. . .
From: arw@pythonpros.com
Date: Mon, 11 May 1998 17:01:48 GMT
To: python-list@cwi.nl
Newsgroups: comp.lang.python
Organization: you want fries with that?

In article <3.0.5.32.19980508100331.007a6970@mail1.lynn.edu>,
  Jason McVay jmcvay@bigfoot.com wrote:


> Sorry for the newbie question everyone, but can someone explain the
> difference among functional, symbolic, mathematical, and any other type o'
> programming related to python?
>
> Thank you,
> jason


Ok: here's the last word in massive oversimplification.

A) Imperative/procedural is the mode of programming closest to
the actual Von Neumann register machine.  You stuff values into
slots and get them out again to do computations, the results of
which you stuff back into other slots (maybe clobbering existing
values).  You also maybe hop around in the program flow using
gotos, or undisciplined mixtures of mutable global variables (fortran
common blocks) and functional abstraction if either (a) you
aren't very good or (b) you want extreme speed or (c) both.
The bad thing about this mode of programming is that it can be
extremely hard to get right or debug -- the good thing is that
it can be optimally fast (using the dominant computer architectures,
which shows no signs of becoming submissive).  In practice
right now, all other modes "compile" to this one.

B) Object *based* programming is a variant of imperative (or other)
programming where the program is architected around the notion
of "objects" -- groups of state variables associated with groups
of operations which operate on those state variables.  Object based
design and methodology makes imperative programming easier because

(1) we live in a world of objects [I don't call scratch(my_cat, me)
directly, instead I call me.kick(my_cat) which results in my_cat(scratch,me)
indirectly, if you know what I mean -- similarly I don't directly
tell the printer to move it's stylus and print characters directly, instead
I call the doc.print(..) operation of a document which calls
device_context.draw(something) which is translated to lower and lower
levels until the printer finally moves its stylus] so object based
methodology maps directly to the way people tend to think...

(2) the effects of operations are delimited by well defined boundaries
-- ie, if the printer prints something weird I don't have to look at
the whole program, only those parts related to device_contexts and
printing (or at least that's where I start looking)...

(3) object interfaces can be organized into patterns which can be
reused, etc (ie, I can get an epson dot-matrix or a hp laser and the
program doesn't notice much important difference: a printer's a printer).

B.1) *structured* programming is object based programming minus the objects,
roughly speaking.  IE, I can call scratch(my_cat, me) but I can't call
extend_claw(left, 3, my_cat).

B.2) Object *oriented* programming is object *based* programming with
a bunch of other stuff tacked on (like inheritance).  Exactly what
gets tacked on is a matter of pointless and heated debate.

The bad news about all object *based* and similar technology is that
you can't really have that last ounce of speed and efficiency -- which is why
people still write new Fortran code for numerical work.  It's
also why C++ is so, uh, feature rich ;c).

C) Functional or applicative programming organizes everything around
function application.  It can be a very powerful mode of programming,
but it often requires deep thought, and you just can't do everything
in a natural way (deep results prove that you *can* do everything,
but don't say anything about the fuzzy notion of "naturalness --
for example,
a printer is simply not a function -- when it runs out of ink, it's
out of ink -- no mathematical magic will make the ink reappear.
I'm very sorry about that.)  Unix programmers are thinking functionally
when they type things like

  % netstat | grep 756 | sort 3 | wc

ie, the output of one thing gets fed into another... result at
the end.  Pure functional programming never allows assigned
variables to *ever* change value (which most conventional programmers
find hard to deal with, like when they want to decrement the
amountoftoner variable).

D) Declarative, or logic programming (and similar things such as SQL)
allow the user to state "what is wanted" or "the properties of
what is wanted" without stating "how to get it".  In practice with
SQL and prolog you generally have a very good idea how the underlying
engine "gets it" and you state your specification accordingly,
especially if performance (or termination in prolog's case) is
required.  Mathematical programming (optimization of math functions,
subject to constraints and penalties and such).
actually should fall here: ie,

   minimize x+y
   subject to x-y>=3 and 4-2*x-7*y<=-9 and 4*x+11*y<=90

system prints x=something and y=something, and you don't know nor
do you care how the answer came to be (but you might check it!).
Very nice for things like databases or inference problems.

Symbolic programming is: mix any one of these styles with symbolic
structures (ie, you manipulate data structures that represent
symbolic objects, such as equations above).

For example: gadfly/sql is a symbolic programming system.

  -- at the highest level it's declarative (SQL) (with controlled
     updates).
  -- just beneith that it's object oriented.
  -- parts benieth that (eg, the query engine) are approximately
     functional (or, more precisely, monotone, a variant of functional).
  -- way down it's imperative (eg, look at kjbucketsmodule.c).

Almost everything can be viewed as a mix like this...
I hardly write a program which doesn't have at least a bit
of functional, object based, and procedural.  You probably
do too, but aren't necessarily aware of it.
   -- Aaron Watters

===
Righteousness is the accordance of actions with what is right,
and the greatest exercise of it is in honoring the worthy.
The decreasing measures of the love due to relatives and the
steps of honor due to the worthy are produced by the principles
of propriety.  -- from the Doctrine of the Mean

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading