[pro] Bottom-up, top-down or both ?

Didier Verna didier at lrde.epita.fr
Fri Mar 11 16:18:10 UTC 2011


It is well known that a functional approach to programming helps
thinking in a top-down fashion. Idioms made available by first-class
functions (e.g. mapping and folding) help you write down the general
ideas first, and worry about the details later. Paul Graham has nice
examples of that in On Lisp IIRC.

In fact, it seems that being able to think in a top-down fashion is not
specifically tied to functional programming, but perhaps more generally
to the level of expressiveness that your language provides.

For example, I find that the very existence of a REPL helps a lot: you
can test a function on manually-provided data, that would normally be
constructed by a lower-level, yet-to-be-written function. You can
pre-define stuff to do nothing but print "I'm here", just to check if
the bigger thing works.

In Lisp, with half-defined generic functions, you can even have your
program half-working, some details remaining to be sorted out later. So
obviously, Lisp being as expressive as it is, is of great help in
thinking top-down.

Even in Lisp, however, some things need to be defined before they can be
used. So I recently discovered, to my greatest astonishment, that even
if my thought process is top-down 99% of the time, my /code/ is *always*
written down in a bottom-up fashion. Occasionally, I might have one of
those quasi-hysterical crisis in which I would spend hours re-organizing
my code until the I get the overall expression of the program as close
as possible to the ultimate upside-down pyramid of dependencies. And
then, we I need to immerse myself again into something I wrote a long
time ago, I usually read my files backwards... or not!

So I was wondering, how's your code organized? How's your thought
process organized? Top-down? Bottom-up? Both?

-- 
Resistance is futile. You will be jazzimilated.

Scientific site:   http://www.lrde.epita.fr/~didier
Music (Jazz) site: http://www.didierverna.com




More information about the pro mailing list