code review

Chris Angelico rosuav at gmail.com
Sun Jul 1 22:04:29 EDT 2012


On Mon, Jul 2, 2012 at 11:28 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Sun, 01 Jul 2012 16:33:15 +1000, Chris Angelico wrote:
>
>> On Sun, Jul 1, 2012 at 4:27 PM, Steven D'Aprano
>> <steve+usenet at pearwood.info> wrote:
>>> Yes, you can find specially crafted examples where adding parentheses
>>> in certain places, but not others, doesn't change the overall
>>> evaluation of the expression.
>>
>> My point was that adding parentheses around the tightest-binding
>> operator is a common, clear, and usually insignificant, way of
>> demonstrating operator precedence. So FOR THAT USE they must not change
>> evaluation of the expression. Obviously if you put them anywhere else,
>> they change evaluation. Nice job knocking down a straw man.
>
> We *really did have* somebody arguing that chained comparisons are Bad
> because you can't stick parentheses around bits of it without changing
> the semantics. That was an actual argument, not a straw-man.

Okay, I take back the "straw man" accusation, and apologize for it.
But you were quoting my text at the time, so I thought you were aiming
at my argument - which, not being that, was what led me to think you
were answering what you weren't answering.

> Chained comparisons in the Python sense may be rare in computer
> languages, but it is the standard in mathematics and hardly needs to be
> explained to anyone over the age of twelve. That is a terrible indictment
> on the state of programming language design.

I'd say that proves that Python is a good language for expressing
mathematics in, then. That's all. Doesn't necessarily mean it's good
for any other task (doesn't mean it's bad either of course). Python
does not, meanwhile, have inbuilt operators for calculus, nor does it
have an equation solver. Do we absolutely need them? Empirically no.
Python can be an excellent language without making every bit of
mathematical notation executable. There are, I am sure, plenty of
cases where it would be nice to go:

x = y+2
x*3 = y*4+7
print("x = %d, y = %d",x,y)

You can argue that Python ought to have more-different operators for
comparison and assignment, but the fact of algebra is that it has
neither - the equals sign is more of a declaration of truth. Algebra
simply isn't imperative. It's fine (and fits the Eliza principle) to
evaluate expressions algebraically, but equations aren't assignment.

ChrisA



More information about the Python-list mailing list