PEP 572: Why not := as standard assignment operator?

Hi list, when reading PEP 572 I actually liked it a lot - I think it's actually a cool idea. I think it's actually that cool an idea that it should be made the default way of doing an assignment, over time phasing out the good ole =. This would have several benefits: - people wouldn't have to worry about two different options - different things would have a different look: assignment is :=, keyword args is =, while comparison is ==. Especially beginners would benefit from this clarity. in this case, for sure, we should make it possible to chain :=s, for example by making it bind right-to-left, so that a := b := 3 would be a := (b := 3) I'm sorry if somebody brought that up already, but the discussion has grown so huge that I couldn't read through it entirely. Greetings Martin

On Thu, Apr 26, 2018 at 11:13 PM, Martin Teichmann <lkb.teichmann@gmail.com> wrote:
Hi list,
when reading PEP 572 I actually liked it a lot - I think it's actually a cool idea. I think it's actually that cool an idea that it should be made the default way of doing an assignment, over time phasing out the good ole =.
This would have several benefits:
- people wouldn't have to worry about two different options - different things would have a different look: assignment is :=, keyword args is =, while comparison is ==. Especially beginners would benefit from this clarity.
in this case, for sure, we should make it possible to chain :=s, for example by making it bind right-to-left, so that a := b := 3 would be a := (b := 3)
I'm sorry if somebody brought that up already, but the discussion has grown so huge that I couldn't read through it entirely.
It has indeed grown huge. And in the interests of not growing it even huger, I'm not going to rehash the arguments against making := into the one and only operator, save to say one thing: there's no way that "x = 1" can be removed from the language any time soon, and by "soon" I mean even by the Yes Prime Minister definition, where "any day now", in strategic terms, meant "within the next half century". For further details, search the archives. Please don't reply to debate this point. :) ChrisA

On 26 April 2018 at 16:18, Chris Angelico <rosuav@gmail.com> wrote:
On Thu, Apr 26, 2018 at 11:13 PM, Martin Teichmann <lkb.teichmann@gmail.com> wrote:
Hi list,
when reading PEP 572 I actually liked it a lot - I think it's actually a cool idea. I think it's actually that cool an idea that it should be made the default way of doing an assignment, over time phasing out the good ole =.
This would have several benefits:
- people wouldn't have to worry about two different options - different things would have a different look: assignment is :=, keyword args is =, while comparison is ==. Especially beginners would benefit from this clarity.
in this case, for sure, we should make it possible to chain :=s, for example by making it bind right-to-left, so that a := b := 3 would be a := (b := 3)
I'm sorry if somebody brought that up already, but the discussion has grown so huge that I couldn't read through it entirely.
It has indeed grown huge. And in the interests of not growing it even huger, I'm not going to rehash the arguments against making := into the one and only operator, save to say one thing: there's no way that "x = 1" can be removed from the language any time soon, and by "soon" I mean even by the Yes Prime Minister definition, where "any day now", in strategic terms, meant "within the next half century".
In the interest of that, do you think := can be made illegal, by the grammar, if used outside an expression? a = 1 # legal a := 1 # Syntax error if a := 1: # legal Thanks in advance. -- Gustavo J. A. M. Carneiro Gambit Research "The universe is always one step beyond logic." -- Frank Herbert

On Fri, Apr 27, 2018 at 1:38 AM, Gustavo Carneiro <gjcarneiro@gmail.com> wrote:
On 26 April 2018 at 16:18, Chris Angelico <rosuav@gmail.com> wrote:
On Thu, Apr 26, 2018 at 11:13 PM, Martin Teichmann <lkb.teichmann@gmail.com> wrote:
Hi list,
when reading PEP 572 I actually liked it a lot - I think it's actually a cool idea. I think it's actually that cool an idea that it should be made the default way of doing an assignment, over time phasing out the good ole =.
This would have several benefits:
- people wouldn't have to worry about two different options - different things would have a different look: assignment is :=, keyword args is =, while comparison is ==. Especially beginners would benefit from this clarity.
in this case, for sure, we should make it possible to chain :=s, for example by making it bind right-to-left, so that a := b := 3 would be a := (b := 3)
I'm sorry if somebody brought that up already, but the discussion has grown so huge that I couldn't read through it entirely.
It has indeed grown huge. And in the interests of not growing it even huger, I'm not going to rehash the arguments against making := into the one and only operator, save to say one thing: there's no way that "x = 1" can be removed from the language any time soon, and by "soon" I mean even by the Yes Prime Minister definition, where "any day now", in strategic terms, meant "within the next half century".
In the interest of that, do you think := can be made illegal, by the grammar, if used outside an expression?
a = 1 # legal a := 1 # Syntax error if a := 1: # legal
No. Any expression may be used as a statement, so this isn't "outside an expression". ChrisA

Chris Angelico wrote:
No. Any expression may be used as a statement, so this isn't "outside an expression".
It could be detected as a special case and rejected some time later in the compilation process. The question is whether it's worth making the rules more complicated just to forbid something that some peple think is bad style. -- Greg

On 4/26/2018 11:38 AM, Gustavo Carneiro wrote:
On Thu, Apr 26, 2018 at 11:13 PM, Martin Teichmann <lkb.teichmann@gmail.com <mailto:lkb.teichmann@gmail.com>> wrote: > when reading PEP 572 I actually liked it a lot - I think it's actually > a cool idea. I think it's actually that cool an idea that it should be > made the default way of doing an assignment, over time phasing out the > good ole =.
Please no, I really, really appreciate not having to see add ':' all the time. Plus, it already has two other uses: end of header and dict key-item separator. Plus, see below.
In the interest of that, do you think := can be made illegal, by the grammar, if used outside an expression?
a = 1 # legal a := 1 # Syntax error if a := 1: # legal
Please no. PEP 572 does not discuss top-level interactive assignments. But it should, because having two forms of assignment that lets one choose to echo or not is a plus. Sometimes one wants to see the result of an assignment. After
a, b = 14387, 344
it would be nice to be able to write
diff := a - b 14343
instead of
diff = a - b diff 14343
I consider this a significant positive feature of the proposal. On the other hand, sometimes one does not want the see the result. A long result is often useless to view and may scroll previous results out of the window. A very long result may scroll previous results out of a finite console buffer altogether. (For Windows Command Prompt, the default is 300 lines, with a max of 9999.) And sometimes the result must not be printed. Tk text widgets (and hence IDLE's Shell) do not have a particular limit on the number of lines. On the other hands, long lines drasticly slow down a text widget, and a long enough line will freeze it. (This is supposed to be fixed in Tcl/Tk 8.7, now in a1 stage.) For instance, ">>> [None]*1000000" in IDLE freezes the process. -- Terry Jan Reedy
participants (5)
-
Chris Angelico
-
Greg Ewing
-
Gustavo Carneiro
-
Martin Teichmann
-
Terry Reedy