Add spaceship assignment operator

php.internals

Nikita Popov

10 years ago
Hi internals! For consistency, we should add a spaceship assignment operator: $a <=>= $b; // same as $a = ($a <=> $b); Additionally, we should add an is-identical assignment operator: $a ==== $b; // same as $a = ($a === $b); Thank you for taking this proposal under consideration. Regards, Nikita

Stas Malyshev

10 years ago
Hi!
> > For consistency, we should add a spaceship assignment operator: > > $a <=>= $b;
Or maybe we shouldn't? Not only it is quite ugly, I am struggling to imagine a use case in which one would need such a construct, and I would recommend rewriting any code that uses such construct.
> Additionally, we should add an is-identical assignment operator: > > $a ==== $b;
This looks like it is a week early. Maybe that was the intent?
-- Stas Malyshev smalyshev@gmail.com

Bob Weinand

10 years ago
> Am 24.3.2016 um 18:50 schrieb Nikita Popov <nikita.ppv@gmail.com>: > > Hi internals! > > For consistency, we should add a spaceship assignment operator: > > $a <=>= $b; > // same as > $a = ($a <=> $b); > > Additionally, we should add an is-identical assignment operator: > > $a ==== $b; > // same as > $a = ($a === $b); > > Thank you for taking this proposal under consideration. > > Regards, > Nikita
I see a problem with that … It’d be impossible to make it consistent with is-equal comparison… === is already is-identical comparison. So, no symbol for the is-equal assignment operator left. As long as you don’t have any better suggestion, I’m sorry, but -1 on that. Bob

Sara Golemon

10 years ago
On Thu, Mar 24, 2016 at 10:56 AM, Bob Weinand <bobwei9@hotmail.com> wrote:
>> $a ==== $b; >> // same as >> $a = ($a === $b); >> > I see a problem with that … It’d be impossible to make it consistent with is-equal comparison… > > === is already is-identical comparison. So, no symbol for the is-equal assignment operator left. > > As long as you don’t have any better suggestion, I’m sorry, but -1 on that. >
Perhaps U+FEFF ZERO WIDTH NON-BREAKING SPACE would help disambiguate it?

Joe Watkins

10 years ago
Morning Nikita, Thanks for all your hard work. Since consistency is one of our main focuses, I move that the discussion period for this extremely important work is moved forward by one week. All in favour, say I. Cheers Joe On Thu, Mar 24, 2016 at 5:56 PM, Bob Weinand <bobwei9@hotmail.com> wrote:

Joe Watkins

10 years ago
Morning Nikita, Apologies for my inconsistent use of language ... I meant to say shortened by one week. Cheers Joe On Thu, Mar 24, 2016 at 6:04 PM, Joe Watkins <pthreads@pthreads.org> wrote:

Mutlu Kocak

10 years ago
+1 On Thursday, 24 March 2016, Nikita Popov <nikita.ppv@gmail.com> wrote:
> Hi internals! > > For consistency, we should add a spaceship assignment operator: > > $a <=>= $b; > // same as > $a = ($a <=> $b); > > Additionally, we should add an is-identical assignment operator: > > $a ==== $b; > // same as > $a = ($a === $b); > > Thank you for taking this proposal under consideration. > > Regards, > Nikita >
-- Mutlu Koçak | Computer Scientist & Engineer Mobile: +420775259871 Parizksa 5, Praha 1 Prague Czech Republic Personal Website: http://www.mtkocak.com

Ryan Pallas

10 years ago
Hi Nikita, On Thu, Mar 24, 2016 at 11:50 AM, Nikita Popov <nikita.ppv@gmail.com> wrote:
> Hi internals! > > For consistency, we should add a spaceship assignment operator: > > $a <=>= $b; > // same as > $a = ($a <=> $b); >
I'm not sure I see a use case for this, when do you compare 2 values and replace one of those values with the result of the comparison? I've literally never done that.
> > Additionally, we should add an is-identical assignment operator: > > $a ==== $b; > // same as > $a = ($a === $b); >
Again, why would you do this? How often are you replacing the contents of a variable with the results of comparing it with something else? $c = $a === $b; $c = $a <=> $b; That seems to be far more common if assigning the results to a variable at all (which is itself not that common for comparisons in my experience).
> > Thank you for taking this proposal under consideration. > > Regards, > Nikita >
Thanks for bringing this up, but I don't see the consistency argument, and I don't feel like its normal use cases at all.

Colin O'Dell

10 years ago
Would your proposal also allow !==== to work? Colin

Sara Golemon

10 years ago
On Thu, Mar 24, 2016 at 11:50 AM, Colin O'Dell <colinodell@gmail.com> wrote:
> Would your proposal also allow !==== to work? >
I think you means !===, which is "not-identical assignment" (!== =) !==== is just *CRAZY TALK* -Sara

Colin O'Dell

10 years ago
You're right! Good call :) On Thu, Mar 24, 2016 at 3:05 PM Sara Golemon <pollita@php.net> wrote:

Nikita Popov

10 years ago
On Thu, Mar 24, 2016 at 8:05 PM, Sara Golemon <pollita@php.net> wrote:
> On Thu, Mar 24, 2016 at 11:50 AM, Colin O'Dell <colinodell@gmail.com> > wrote: > > Would your proposal also allow !==== to work? > > > I think you means !===, which is "not-identical assignment" (!== =) > > !==== is just *CRAZY TALK* >
We shouldn't dismiss such things out of hand, Sara. Consider the following argument: There is a binary !== operator. The compound assignment version of it is !===. But that again is a binary operator! So there should be a !==== compound assignment operator as well. By induction over the natural numbers it follows that !== followed by an arbitrary number of =s should be a valid compound assignment operator. However, when considering the expansion, we see: $a !==== $b; // same as $a = $a !=== $b; // same as $a = $a = $a !== $b; It is now evident that $a !==== $b (or any additional number of =s) has the same meaning as $a !=== $b. A difference could only arise if the left-hand side is an object implementing __set or ArrayAccess, in which case !==== would cause an additional call to __set / offsetSet. Given that !==== and !=== would be, apart from the edge-case of overloaded objects, identical, I must concur with your original judgement that only supporting !=== is sufficient. Thanks, Nikita

Mutlu Kocak

10 years ago
he is trolling :) On Thursday, 24 March 2016, Nikita Popov <nikita.ppv@gmail.com> wrote:
> On Thu, Mar 24, 2016 at 8:05 PM, Sara Golemon <pollita@php.net > <javascript:;>> wrote: > > > On Thu, Mar 24, 2016 at 11:50 AM, Colin O'Dell <colinodell@gmail.com > <javascript:;>> > > wrote: > > > Would your proposal also allow !==== to work? > > > > > I think you means !===, which is "not-identical assignment" (!== =) > > > > !==== is just *CRAZY TALK* > > > > We shouldn't dismiss such things out of hand, Sara. Consider the following > argument: > > There is a binary !== operator. The compound assignment version of it is > !===. But that again is a binary operator! So there should be a !==== > compound assignment operator as well. By induction over the natural numbers > it follows that !== followed by an arbitrary number of =s should be a valid > compound assignment operator. > > However, when considering the expansion, we see: > > $a !==== $b; > // same as > $a = $a !=== $b; > // same as > $a = $a = $a !== $b; > > It is now evident that $a !==== $b (or any additional number of =s) has the > same meaning as $a !=== $b. A difference could only arise if the left-hand > side is an object implementing __set or ArrayAccess, in which case !==== > would cause an additional call to __set / offsetSet. > > Given that !==== and !=== would be, apart from the edge-case of overloaded > objects, identical, I must concur with your original judgement that only > supporting !=== is sufficient. > > Thanks, > Nikita >
-- Mutlu Koçak | Computer Scientist & Engineer Mobile: +420775259871 Parizksa 5, Praha 1 Prague Czech Republic Personal Website: http://www.mtkocak.com

James Titcumb

10 years ago
On 24 Mar 2016 19:43, "Mutlu Kocak" <mtkocak@mtkocak.net> wrote:
> > he is trolling :) >
I wouldn't dismiss this idea straight off. I can see a lot of practical uses for chaining assignment operators, like: $a !==<=>==== $b; Expanded from: $a = $a !== (($a <=> $b) === $b); Which is something I often do in my production applications. In fact I typed this exact use case about 12 times just today. It's a good, expressive way of simplifying code and increasing readability. This would really complete the language IMO.

Midori Kocak

10 years ago
actually it could be proposed to C in 1970 in a same manner for += operator by saying +== and +=== and also +====. But hence Dennis Ritchie is dead and he accepted += as a founding father, we have no chance to ask him. Can we ask maybe to Bjarne Stroustrup as being one of another founding fathers? Is there anyone being in contact with him?

Alain Williams

10 years ago
On Thu, Mar 24, 2016 at 09:16:50PM +0100, Midori Kocak wrote:
> actually it could be proposed to C in 1970 in a same manner for += operator by saying +== and +=== and also +====. But hence Dennis Ritchie is dead and he accepted += as a founding father, we have no chance to ask him. Can we ask maybe to Bjarne Stroustrup as being one of another founding fathers? Is there anyone being in contact with him?
from what I can remember of the PDP-11 instruction set the ++ and -- operators were put into C because there were op codes that did that, that is what someone told me some 35 years ago. We keep them because all Unixy languages have them.
-- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include <std_disclaimer.h>

Alain Williams

10 years ago
On Thu, Mar 24, 2016 at 06:50:17PM +0000, Colin O'Dell wrote:
> Would your proposal also allow !==== to work?
That would be: !=== (one less '=') There should also be: === and !== which are the compare-with-type-juggling and assign operators. So you have assignment operators: ==== !=== === !== Comparison operators: === !== == != I must confess to checking the date when I first saw the proposal.
-- Alain Williams Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT Lecturer. +44 (0) 787 668 0256 http://www.phcomp.co.uk/ Parliament Hill Computers Ltd. Registration Information: http://www.phcomp.co.uk/contact.php #include <std_disclaimer.h>

Pierre Joye

10 years ago
Hi Nikita, On Fri, Mar 25, 2016 at 12:50 AM, Nikita Popov <nikita.ppv@gmail.com> wrote:
> Hi internals! > > For consistency, we should add a spaceship assignment operator: > > $a <=>= $b; > // same as > $a = ($a <=> $b);
I miserably fail to imagine any use case for this.
> Additionally, we should add an is-identical assignment operator: > > $a ==== $b; > // same as > $a = ($a === $b); > > Thank you for taking this proposal under consideration.
Besides the comment about that one from Sara, I also fail to remotely imagine why one would need that. In short, yes, it is consistent but it is really unreadable, at best.
-- Pierre @pierrejoye | http://www.libgd.org

Yasuo Ohgaki

10 years ago
Hi all, On Fri, Mar 25, 2016 at 11:25 AM, Pierre Joye <pierre.php@gmail.com> wrote:
> On Fri, Mar 25, 2016 at 12:50 AM, Nikita Popov <nikita.ppv@gmail.com> wrote: >> Hi internals! >> >> For consistency, we should add a spaceship assignment operator: >> >> $a <=>= $b; >> // same as >> $a = ($a <=> $b); > > I miserably fail to imagine any use case for this. > >> Additionally, we should add an is-identical assignment operator: >> >> $a ==== $b; >> // same as >> $a = ($a === $b); >> >> Thank you for taking this proposal under consideration. > > Besides the comment about that one from Sara, I also fail to remotely > imagine why one would need that. > > In short, yes, it is consistent but it is really unreadable, at best.
The same impression. I suppose there aren't much use cases, are there? Regards,
-- Yasuo Ohgaki yohgaki@ohgaki.net

Dmitry Stogov

10 years ago
I hope this is a joke. Lets try not to reinvent Perl. Thanks. Dmitry. ________________________________________ From: Nikita Popov <nikita.ppv@gmail.com> Sent: Thursday, March 24, 2016 20:50 To: PHP internals Subject: [PHP-DEV] Add spaceship assignment operator Hi internals! For consistency, we should add a spaceship assignment operator: $a <=>= $b; // same as $a = ($a <=> $b); Additionally, we should add an is-identical assignment operator: $a ==== $b; // same as $a = ($a === $b); Thank you for taking this proposal under consideration. Regards, Nikita