[racket-dev] P4P: A Syntax Proposal

From: Guillaume Marceau (gmarceau at gmail.com)
Date: Sat Jul 31 00:38:08 EDT 2010

On Fri, Jul 30, 2010 at 10:52 AM, Matthias Felleisen
<matthias at ccs.neu.edu> wrote:
> Programmers who complain about parens mean something larger:
>  -- the entire syntax (it doesn't look traditional)
>  -- the entire semantics (function calls dictate nearly everything)
>  -- the way we program (inductive structures have more weight than indexed ones)
> and more and certainly all the 'syntactic' symptoms that come with this:
>  -- nested expressions show up a lot; how to read them
>  -- array/for-loop "patterns" of programming aren't working, how to start?
>  -- why this focus on data representations, can't we just use arras?
> And I am sure the list of such make-me-feel-bad unfamiliarities goes on.

I'll give a different theory.

My theory starts with the observation that students who program in BSL
spend an inordinate amount of time fiddling with parentheses. It's
exhausting, non-fun work. I think students are blaming the
parentheses simply because that is what is under their nose most of
the time.

One thing we have learned from the interviews is, they might hate the
parentheses, but they love the gray highlight tool of DrRacket. By
mid-semester, they use it accurately, and skillfully. Their technique
looks like this: the student clicks on a closing parenthesis, sees
which constructs it is closing, and then tries to remember the
original intention for that closing parenthesis. They are checking
whether that parenthesis is closing what they meant it to close. This
takes a lot of time, as they are constantly re-inferring the
intentionality of their closing parentheses.

Professional programmers don't do this. Why not?

First, we rely on indentation, visually, and also procedurally. We
press "tab" on a line that should be correctly indented, and if the
line moves, we know there is a problem. Second, we don't adjust
parentheses one at the time. After editing a section of code, we
delete the entire block of closing parentheses, "))])]))", then we
press close until the next line tabs to the right place.

I've never seen student in a beginner course work this way. As an
experiment, I invite you to try programming without using tab, and
without deleting blocks of parenthesis at once. I suspect you will
develop sympathy for these students who "hate parentheses".

Why would this be less of a problem in curly brace languages?

First, there are just many more parentheses in a Racket program. As
Matthias was saying, we use a lot of nested expressions, and function
call dictate nearly everything. So, in a curly brace language, when a
student is trying to re-infer their parenthesis structure, there are fewer
of them, so it isn't as hard.

Second, the grammar markers in a curly brace language have names on
them. They use "then" to separate the predicate from the answer, we
use ")(". It is much easier to re-infer intentionality of the former.
The latter is just another a bunch of parenthesis floating amongst
other anonymous parentheses.

If this theory holds, then P4P should help a great deal. P4P enforces
indentation, so students will have to start paying attention to it
(they really don't at the moment). P4P also reduces the number of
parentheses overall, and it puts names on the grammar markers.

I concur with Shriram. I don't think prefix notation for arithmetic is
a problem. Early in the course they will sometime write an infix
expression by mistake, but the error message they receive quickly
prompts them to the right fix. I don't see them struggling with this.
I also don't think "I hate parentheses" comes from familiarity with
some other syntax, or from familiarity with arrays. The feeling seem
just as common amongst non-majors who have never seen any programming

Posted on the dev mailing list.