3 ms·
> > in OK?, 5 + 2 * 3 evaluates to 21, not 11, because addition and multiplication have equal operator precedence. > wtf To be honest, I think this is actuall
by still_grokking 4y ago
> > in OK?, 5 + 2 * 3 evaluates to 21, not 11, because addition and multiplication have equal operator precedence.
> wtf
To be honest, I think this is actually smart!
There are to this day people in coding that don't know about operator precedence. I've seen bugs because of that not only once…
Just having a very simple rule and making everything else explicit is not bad for a computer language. You know, explicit is better than implicit. At least some serpents said that.
Also:
https://www.pyret.org/docs/latest/op-precedence.html#%28part._.But_why_not_use_precedence_%29 https://www.pyret.org/docs/latest/op-precedence.html#%28part...
[Please note that Pyret "is a programming language designed to serve as an outstanding choice for programming education" according to its web-site]
https://en.wikipedia.org/wiki/Smalltalk#Expressions https://en.wikipedia.org/wiki/Smalltalk#Expressions
https://en.wikipedia.org/wiki/APL_syntax_and_symbols#Syntax_rules https://en.wikipedia.org/wiki/APL_syntax_and_symbols#Syntax_...
- jll29 4y ago> > in OK?, 5 + 2 * 3 evaluates to 21, not 11, because addition and multiplication have equal operator precedence. >To be honest, I think this is actually smart! A better way to implement this is to always enforce parentheses around binary operators - which avoids misleading someone who is used to mathematical precedence (whether it is from maths or from using other languages).
- still_grokking 4y agoNot everybody likes LISP's syntax though. ;-) I actually think what Pyret does is reasonable.
- PeeMcGee 4y agoHonestly confused why the concept of some arbitrary "order of operations" was ever entertained at all. You'd think ye olde algebraists would have recognized the ambiguity as a glaring problem right away. After a bit of light searching I'm still struggling to find any historical reasoning behind it.