[Fluxus] whitespace and scheming

Dave Griffiths dave at pawfal.org
Thu Dec 6 02:55:25 PST 2007


Hi all,

A lot of people using fluxus are new to scheme, and although I still feel
fairly new to it myself, and don't want to get all 'preachy' - this is
something which might help with common readability problems people have...

Whitespace is not a mandatory feature of the language like it is in
python, but maybe it should be... when indentation has gone wrong it's
nearly impossible to read scheme.

I notice I tend to read the indentation first and not really notice the
parentheses - they sort of back up what the indentation tells me, and add
some detail where needed.

The great thing about being indentation-strict is that it makes
missing/extra parentheses much more obvious.

(define (a-func a b c) <- missing ) so indent next lines until...
    (do-something a b c)
    (do-something2 c)) <- an extra ) so indent back

(something-else-entirely)

So any time the level changes it's backed up by the fact there are missing
or extra parentheses on the previous line. When this isn't true you're
probably looking at a syntax error.

I think it's also partly to do with not trying to squash to much on one line:

(define (a-func a b c)
    (do-something (do-something-with (foo a)) b (do-something-else-with c))
               starting to get confusing ^    ^
    (do-something2 c))

so spread out!

(define (a-func a b c)

    (do-something                 <- missing ) so indent until...
        (do-something-to (foo a))
        b
        (do-something-else-to c)) <- an extra ) so indent back
        ^ all level - so correspond to args for the do-something procedure

    (do-something c))

There are probably much better examples, but I think this sort of style is
where it moves away from the C like languages, which try to prevent too
much indentation, because it breaks readability for them (which is why
tabs default to 8 on things like MSVC - to prevent you going too deep).

This might be partly due to the fact that procedures tend to be much
longer in C & friends (or so I've noticed in my code) and when indentation
crosses screenfulls of code it's not good at all!

Certainly, if that happens in scheme, or the level of indentation gets
completely ridiculous, it tells you it's time to break it down into
smaller, more readable procedures.

And yes, we need to add automatic indentation like drscheme has - I
certainly use it all the time there.

cheers,

dave




More information about the Fluxus mailing list