3 ms·
> Should always be able to be read top-to-bottom, left-to-right. No <expression> if <condititonal> like in Ruby. I believe that rules out operator precedence,
by riffraff 5y ago
> Should always be able to be read top-to-bottom, left-to-right. No <expression> if <condititonal> like in Ruby.
I believe that rules out operator precedence, which is customary to copy from math, for good reasons.
Not all languages do (e.g. smalltalk) but I'm not sure it's what the author intended.
- naniwaduni 5y agoSomething people often miss about operator precedence in math is that it very closely tracks implied grouping by spatial orientation of the operands in conventional notation. The "rules" are a formalization of an implied intuitive ordering of operations. This intuition is pretty well lost in programming language operator precedence tables.
- earleybird 5y agoThere are the basic math precedences which language designers then extend with various others. To paraphrase Guy Steele[0] - with the exception of what you learnt in high school, precedence should be eliminated from languages. [0] any of his talks/papers on meta notation - sorry I don't have a link handy
- redbar0n 5y agomaybe not even with the exception of what you learnt in high school…? It was ambivalent then, and people even struggle with remembering and applying PEMDAS years later.. wouldn’t it be better - for humans & computers alike - if application of algebra was completely uniform, chronological, and predictable?
- SomeHacker44 5y agoAPL evaluates strictly in left to right order. It is very odd to me initially to have uniform precedence when dealing with math.
- redbar0n 5y agoGood point. Smalltalk is a source of inspiration, though I am unaware of how it handles math expressions in particular. The solution as I see it: You’d have to enforce using parentheses (in line with «explicit over implicit»), alternatively enforce an ordering of math expressions so that the operators with the highest precedence has to be placed first. This might even be beneficial in tail call optimization, since it minimizes what has to be kept in memory (for the compiler as well as the human reader).
- scroot 5y ago> I am unaware of how it handles math expressions in particular. It does not automatically do order of operations. You have to explicitly use parentheses, as you say. However methods in Smalltalk tend to be quite short do to the nature of the system so it tends to not be as messy as one might expect.
- lolinder 5y agoI don't think that enforcing an order of expressions would help at all with optimization, since it's just a syntactic requirement. You should end up with an equivalent abstract syntax tree, and as a result the same underlying machine code.