[Python-Dev] PEP 572: Do we really need a ":" in ":="?
tim.peters at gmail.com
Thu Jul 5 22:10:24 EDT 2018
>>> I also think that the dreadfulness of mistyping = where == is expected
>>> is exaggerated.
>> There are a number of core devs who would be rabidly opposed
>> to allowing that confusion in Python, due to still-remembered
>> real-life nightmares in C. For example, me ;-) It only takes one
>> wasted day of debugging that typo in a time-critical project to sour
>> you on it for life, and several of us run out of fingers counting the
>> number of days it actually did cost over our C careers.
> I still do quite a bit of C programming and I have exactly the opposite
Meaning that confusing "=" and "==" in C _saves_ you days of debugging in
time-critical projects? ;-)
> given modern environments: why is gcc/clang/vs complaining about if (x=a)
> I know what I am doing!
Because gcc/clang/vs is acknowledging how widely and deeply this C wart is
despised. Isn't that obvious? You're quite the exception here, not "the
rule" - as gcc/clang/vs eternally but apparently futilely remind you ;-)
> Seriously, ':=' looks like a reluctantly introduced kludge to allow
> assignment in expressions.
There have been piles of other suggestions, but ":=" remains the least
disliked (at least by Guido, and his opinion actually counts ;-) ).
> We agree that it is sometimes useful to have, but we will make the feature
> really hard to use
? It's very easy to use. Try it - I have. But I've used several
languages in which ":=" was _the_ way to spell assignment, so it felt
familiar at first touch.
> or discover.
It doesn't even exist yet, but Googling on
python operator :=
already returns a directly relevant hit on the first page for me:
The hits above it are all to overviews of Python operators. Here on
Windows, the interface to the Python doc files in IDLE contains an entry
for each operator, so just typing := in the index search box will
eventually go directly to its docs. If you can't do something similar on
Linux, upgrade to Windows ;-)
> What happened to the "consenting adults" philosophy?
Struggling mightily the last several months to get consensus on some form
of embedded assignment _at all_ :-(
> Do we want to protect users who cannot tell = from ==
> so much that we are willing to cause Python to be the first language
> with two non-interchangeable assignment operators?
Sure - I am. _Far_ more than I'm willing to reproduce C's mistake. It's
one of the first things singled out in Andrew Koenig's "C Traps and
Pitfalls", starting with his original paper that was the basis for his 1989
book of the same name:
You can use Google too - it's a top-10 item in every list of "C warts" I've
ever seen. It's impossible to overstate how hated it is.
But, sure - if you post in its defense a few more times, everyone sensible
is sure to change their mind - and I'll ask Andrew to remove that section
from his still-selling book ;-)
I solved the problem in my own code by using an editor that displays a
single "=" in C source as a left-arrow graphic (that's one of its
C-specific display options - again a response to how notorious this
bug-magnet is). So assignment and equality-testing in C code look entirely
different to me, regardless of context.
But to this day, I routinely get a SyntaxError when writing new Python code
because I _think_ "if x equals y" and _type_ "if x = y:". So I know for
sure that it's still a typo I'm way too prone to make.
I've picked up that you're not, but that's scant comfort ;-)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev