3.2 Overview: MUF (cont'd)
Organizing Your Code:
Recall that MUF is a `structured' language: as long as
the statements in a function are in the same order, reading top to
bottom and left to right, and as long as they are separated by
whitespace, it doesn't matter how you place them on the page.
`Whitespace' is any combination of spaces, tabs, or line breaks.
Instead of...
: main
me @ "Hello, world!" notify
"mink" "otter" "linsang"
pop pop pop
;
We could have written...
: main me @ "Hello, world!" notify "mink" "otter" "lingsang" pop pop pop ;
Or even...
: main me
@
"Hello, world!"
notify "mink"
"otter"
"linsang"
pop
pop
pop
;
All three versions would mean the same thing to the compiler, would use
the same amount of memory, and would be executed in exactly the same
way. To most people, however, the first version would be much more
clear. Arrange your code in such a way that its format illustrates or
reinforces logical relationships (that is, combine things that go
together and separate those that don't).
MUF is not case sensitve: POP,
Pop, and pop would all be treated the same
way. Capitalization, therefore, can be used as another way to format
code. For example, you might choose to capitalize all function names and
begin all variable names with lower case to concisely indicate their
difference. Some coders use all capitals for primitives. This does
clearly indicate their difference, but many people find all caps less
readable than upper-lower case. Choose your own style, but remain
consistent within a program.
Now we'll (completely) rewrite tinker.muf several times, with each
version introducing an important aspect of MUF programming.
The > signs and other formatting information have been omitted from
the remaining examples, so you can cut and paste from this file into the
one you're working on.
prev |
toc |
top |
next
|