On Fri, Aug 12, 2011 at 1:09 PM, Chris Angelico <ros...@gmail.com> wrote:
> On Fri, Aug 12, 2011 at 6:57 PM, rantingrick <rantingr...@gmail.com> > wrote: > > I'm glad you brought this up! How about this instead: > > > > a = x + y * z > > > > ...where the calculation is NOT subject to operator precedence? I > > always hated using parenthesis in mathematical calculations. All math > > should resolve in a linear fashion. 3+3*2 should always be 12 and NOT > > 9! > > Why is left-to-right inherently more logical than > multiplication-before-addition? Why is it more logical than > right-to-left? And why is changing people's expectations more logical > than fulfilling them? Python uses the + and - symbols to mean addition > and subtraction for good reason. Let's not alienate the mathematical > mind by violating this rule. It would be far safer to go the other way > and demand parentheses on everything. > Left-to-right is more logical because that is the choice made by the English language (which I will note, we are using right now). Also, ignoring operator precedence, left-to-right is the way math equations evaluate. See 4 / 2 * 3 - you get 6, not (2/3) and not (3/2). Now, I would not suggest changing the multiplication before addition rule, for the very reason you mention: in many cases, the established rule is expected, but that does not mean it is more logical. Chris
-- http://mail.python.org/mailman/listinfo/python-list