=- and -= snag

avi.e.gross at gmail.com avi.e.gross at gmail.com
Mon Mar 13 21:09:52 EDT 2023


Morten,

Suggesting something is UNPYTHONIC is really not an argument I take
seriously.

You wrote VALID code by the rules of the game and it is not a requirement
that it guesses at what you are trying to do and calls you an idiot!

More seriously, python lets you do some completely obscure things such as
check whether some random object or expression is truthy or not. There is no
way in hell the language, as defined, can catch all kinds of mistakes.

Now some languages or their linters have chosen to provide warnings of code
that may be valid but is often an error.

Consider:

  x  = 1
  y = 0
  x = y

Do I want to rest x to the value of y? Maybe. Or do I want the interpreter
to print out whether x == y perhaps?

Well what if the third line above was 

  x  == y

Is that too a warning? 

To add to the confusion some languages have an ===, :=, +=, -=, /=, |= or
oddities like %=% and many of these are all variations on meanings vaguely
related to equality before or after ...

So, no, it is not only not unpythonic, in my opinion, but quite pythonic to
let the interpreter interpret what you wrote and not know what you meant.

Is there possible a flag that would require your code to use spaces in many
places that might cut down on mistakes? There could be and so your example
of something like "new =- old" might be asked to be rewritten as "new = -
old" or even "new = (-old)" but for now, you may want to be more careful.

I do sympathize with the problem of a hard to find bug because it LOOKS
RIGHT to you. But it is what it is.

Avi

-----Original Message-----
From: Python-list <python-list-bounces+avi.e.gross=gmail.com at python.org> On
Behalf Of Morten W. Petersen
Sent: Monday, March 13, 2023 5:26 PM
To: python-list <Python-list at python.org>
Subject: =- and -= snag

Hi.

I was working in Python today, and sat there scratching my head as the
numbers for calculations didn't add up.  It went into negative numbers,
when that shouldn't have been possible.

Turns out I had a very small typo, I had =- instead of -=.

Isn't it unpythonic to be able to make a mistake like that?

Regards,

Morten

-- 
I am https://leavingnorway.info
Videos at https://www.youtube.com/user/TheBlogologue
Twittering at http://twitter.com/blogologue
Blogging at http://blogologue.com
Playing music at https://soundcloud.com/morten-w-petersen
Also playing music and podcasting here:
http://www.mixcloud.com/morten-w-petersen/
On Google+ here https://plus.google.com/107781930037068750156
On Instagram at https://instagram.com/morphexx/
-- 
https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list