POV-Ray : Newsgroups : povray.off-topic : A comparison : A comparison Server Time
10 Oct 2024 17:21:39 EDT (-0400)
  A comparison  
From: Orchid XP v7
Date: 18 Mar 2008 15:16:57
Message: <47e02339$1@news.povray.org>
Compare these two psuedocode snippets:

   To compute SUM(LIST):
     1. Let TOTAL = 0.
     2. Let POSITION = first node of LIST.
     3. Let TOTAL = TOTAL + value at POSITION.
     4. Let POSITION = next node after POSITION.
     5. If POSITION is not the end of the list, go to step 3.

And now, the Other Way:

   1. If LIST is the empty list then SUM(LIST) is defined as 0.
   2. Otherwise, SUM(LIST) is defined as the first element of LIST + 
SUM(rest of LIST).

Personally, several things strike me here.

1. The first version seems a very long and wordy way of explaining 
something that (to a human) is actually quite simple.

2. The second version is very much shorter. (And simpler?)

3. The second version looks like some kind of a riddle. Not a hard 
riddle, but a somewhat baffling definition all the same.

I think it neatly demonstrates the fundamental difference in the mental 
model between imperative and functional programming though. Even a 
layman who knows nothing about programming would (I suspect) appriciate 
that these two methods are pretty different. (And without having to go 
into a long lecture about how computers work, how to program in any 
specific language, etc.)

Anybody else have anything to add?

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.