Language Syntax Suggestion

Matthew Tuck matty@box.net.au
Tue, 09 Mar 1999 22:07:19 +1030


Hans-Dieter.Dreier@materna.de wrote:

> Since I have no built-in parentheses matcher in my brain, I have to
> rely on pretty printing if there are too many of them. The editor that
> came with the package I tried (a long time ago) didn't do
> automatically, however, and there always arises the question where to
> break the lines.

This might be a tricky problem actually.  I usually say to break lines
after the operator, and try to break them on an operator as far to the
top of the expression as possible.

>> By writing all operations in this way the user is
>> never bothered with learning rules of precedence or of context.
>> Precedence is only necessary in languages where the language creator
>> uses function names to separate arguments rather than using brackets and
>> commas. Why have precedence rules when you don't need them?
> In everyday programming life some combinations occur more often than
> others. Precedence rules are created to minimize the use of parentheses
> (so users won't get lost, see above). If there are not too many
> operators (or groups of similar operators sharing a predence rule),
> they are learned quite easily.

This is the trick of course.  I think in practice most precedence rules
are useless.  I find I usually just use brackets anyway because I can't
be bothered thinking about the rules.

I'm more inclined to define "operator groups", like + and -, * and /. 
Members of the group can be used next to other members in the group, but
to combine with a member of another group you need to bracket.  The
groups have no ordering as such, like "higher precedence".

So 3 + 4 - 1 is allowed, but 3 - 4 * 1 isn't.  Other than losing the
multiplicative/additive precedence which most people know, this should
avoid most examples of bracketitis while remember that most other cases
of precedence are bracketed by the programmer anyway.

-- 
     Matthew Tuck - Software Developer & All-Round Nice Guy
             mailto:matty@box.net.au (ICQ #8125618)
       Check out the Ultra programming language project!
              http://www.box.net.au/~matty/ultra/