[plt-scheme] Imperative programming : missing the flow
I'm hoping that others here can point me to existing work on this
topic, or help to refine this idea for me.
I'm teaching Java to first-year students, and we're about to walk off
a cliff and start programming imperatively. I've done this
transition several times now, and it occurs to me that what's most
irritating to me about the imperative style is the lack of "flow".
What do I mean by flow? Simply that each expression produces a
result that is used by another expression. In imperative
programming, by contrast, I feel that I have a bunch of statements
lying on the floor, and that their order is both important and
difficult to explain clearly.
Here's a simple example of the difference: take a functional
program. remove a subexpression. Does it still compile? Probably
not. In contrast: take an imperative program. Remove a statement.
Does it still compile? Sure it does, and does the wrong thing.
This problem is inverted when we're talking about program
construction (the job of a programming teacher). How do I write a
function? Well, in a functional program I can start "at the top"
with the outermost constructor for the result and proceed inward.
How do I know when I'm done? Well, the program won't compile until
I supply all of the pieces. To construct an imperative function, by
contrast--especially one of type void--I can simply write "return;".
How do I know when I've got all the pieces? I don't have a good
answer here.
In fact, a better name for this might not be "functional", but rather
"algebraic," in the sense that program fragments are combined
algebraically to form programs.
Once again; can anyone point me to existing work, or tell me that I'm
wrong?
John Clements
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2223 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20070511/b8a297bd/attachment.p7s>