code review

Rick Johnson rantingrickjohnson at gmail.com
Mon Jul 2 17:16:24 CEST 2012


On Jun 30, 9:06 pm, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> On Sun, 01 Jul 2012 00:05:26 +0200, Thomas Jollans wrote:
> > Yes. My sole point, really, is that "normally", one would expect these
> > two expressions to be equivalent:
>
> > a < b < c
> > (a < b) < c
>
> Good grief. Why would you expect that?
>
> You can't just arbitrarily stick parentheses around parts of expressions
> and expect the result to remain unchanged. Order of evaluation matters:
>
> 2**3**4 != (2**3)**4

Yes but as Chris points out in the next message, you can inject the
following parenthesis without changing a thing!:

py> 1 + 3 * 4
13
py> 1 + (3 * 4)
13

Of course i understand the rules of operator precedence, however i
have never liked them AND i continue to believe that such
functionality breeds bugs and is in fact bad language design. I
believe all evaluations should be cumulative:

py> 1 + 3 * 4
should ALWAYS equal 16!

With parenthesis only used for grouping:
py> a + (b*c) + d

Which seems like the most consistent approach to me.




More information about the Python-list mailing list