Order of precedence

Eliot & Linda Miranda elcm at pacbell.net
Wed Jan 27 18:28:34 UTC 1999


Ian Bicking wrote:

> In message Tue, 26 Jan 1999 09:38:32 -0800,
>   glenn <krasner at objectshare.com>  writes:
> >       c) cater to adults and children already computer-skilled who have
> > preconceived notions set by some other computer languages which have
> > multiple rules, one operator-based and the other left-to-right (or
> > right-to-left or some such).
>
> I'm not saying that the normal, mathematical rules of precedence are easier
> for children.  Quite the contrary -- Smalltalk's simple left-to-right rule
> is much more intuitive.  This is the problem.  A child who is introduced to
> Smalltalk's system would likely have their intuition reinforced, making it
> all the harder to learn the proper (mathematical notation) rules of
> precedence.
>
> The fact of the matter is, mathematics says that 3+4*5=23.  You can't change
> that -- the mathematical conventions of the world are not going to be
> changed because they are easier for the computer to parse.  In a practical
> matter, those conventions have been created because they *are* easier to
> parse (for humans) in real-world situations.  They lead to less parenthesis.
> They group factors.  They *are* aesthetic.

Nobody seems to have pointed out that the binary operators are not just mathematical operators.  The binary operators are in fact an arbitrary and extensible set of infix message selectors, some of which just happen to be used for some mathematical operators.  e.g. there's no binary exponentiation operator in the original Smalltalk-80, one uses raisedTo:.  e.g. @ constructs points and isn't a mathematical operator at all.  So changing the precedence rules for infix operators would unnecessarily complicate the other, and equally valid, uses of these operators.

I've taught undergraduate and post-graduate courses in Smalltalk and have had students that liked and disliked the infix precedence rules.  But I've never encountered a student that didn't get the rules pretty quickly.  The left-to-right rule is so simple that even though one may not like it one can learn it really quickly.


> Perhaps the real answer is to have a view of Squeak where the syntax is
> fully mathematical.  Where 3*sin(x^2+2) works.  In this view a child could
> learn mathematics.  But it seems that a better solution could be made, one
> that encompasses both needs (simplicity and conformity) instead of requiring
> a break-away syntax.

So we're supposed to do without #==, #~~, #->, #@?  And where does mathematics define commonly taught and understood precedence rules which include the relational operators?  What are the relative precidences of + - * / \\ // < <= > >= = ~= ?  What's the scheme for defining the precedence of new operators a programmer might introduce?  How can one ensure that different programmers use the same precedence order if they both introduce a new operator?  Or is maintaining readability less important than attempting to provide an inaccurate simulation of mathematical notation (e.g. * instead of adjacency)?

> I bring this up because I've been looking at Logo, and one of the big
> compromises they made in the syntax was to allow infix notation even though
> it wasn't part of the Lisp tradition and sullied the syntax quite a bit.

But Smalltalk's solution doesn't sully the syntax at all.

> Now, this is all assuming that a goal of Squeak (distinct from Smalltalk)
> is as a pedagogical tool.  This is by no means necessarily true... though
> it would be neat if Squeak could be used by children, that doesn't mean it
> needs to be created for them to learn from it (though, of course, it is
> impossible to seperate use from learning).  Pedagogically, introducing
> something that looks almost like proper mathematical expressions but isn't
> is a bad thing to do.  This is one reason (not necessarily a huge reason)
> that I don't think Squeak is ready for children.

I don't accept the argument that its good pedagogics to maintain an inaccurate and partial simulation of common mathematical notation.  I do accept the argument that its good pedagogics to use simple but adequately powerful rules.  I think very strongly that the current design of the infix rules is better than any other programming language I've used, that its easier to teach, that its easier to learn, and easier to use.

_______________,,,^..^,,,_______________
Eliot Miranda, ParcPlace





More information about the Squeak-dev mailing list