# Add spaceship assignment operator

- Thread: https://externals.io/message/91907
- Original archive: https://news-web.php.net/php.internals/91907
- Started by Nikita Popov on 2016-03-24T17:50:22+00:00
- Messages: 20
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #91907 — Nikita Popov — 2016-03-24T17:50:22+00:00

URL: https://externals.io/message/91907#91907

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

---

## #91908 — Stanislav Malyshev — 2016-03-24T17:55:54+00:00

URL: https://externals.io/message/91907#91908 · In reply to: #91907

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

---

## #91909 — Bob Weinand — 2016-03-24T17:56:50+00:00

URL: https://externals.io/message/91907#91909 · In reply to: #91907

> 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

---

## #91910 — Sara Golemon — 2016-03-24T17:59:11+00:00

URL: https://externals.io/message/91907#91910 · In reply to: #91909

> > […]
> 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?

---

## #91911 — Mutlu Kocak — 2016-03-24T18:00:53+00:00

URL: https://externals.io/message/91907#91911 · In reply to: #91907

+1



> 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

---

## #91912 — Joe Watkins — 2016-03-24T18:04:22+00:00

URL: https://externals.io/message/91907#91912 · In reply to: #91909

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



>
> > […]
>
> 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

---

## #91913 — Joe Watkins — 2016-03-24T18:05:54+00:00

URL: https://externals.io/message/91907#91913 · In reply to: #91912

Morning Nikita,

    Apologies for my inconsistent use of language ... I meant to say
shortened by one week.

Cheers
Joe



> 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
>
> 
>
> > […]

---

## #91915 — Ryan Pallas — 2016-03-24T18:33:39+00:00

URL: https://externals.io/message/91907#91915 · In reply to: #91907

Hi Nikita,



> 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.

---

## #91917 — Colin O'Dell — 2016-03-24T18:50:17+00:00

URL: https://externals.io/message/91907#91917 · In reply to: #91907

Would your proposal also allow !==== to work?

Colin

---

## #91918 — Sara Golemon — 2016-03-24T19:05:44+00:00

URL: https://externals.io/message/91907#91918 · In reply to: #91917

> Would your proposal also allow !==== to work?
>
I think you means !===, which is "not-identical assignment" (!== =)

!==== is just *CRAZY TALK*

-Sara

---

## #91919 — Colin O'Dell — 2016-03-24T19:13:44+00:00

URL: https://externals.io/message/91907#91919 · In reply to: #91918

You're right! Good call :)



> On Thu, Mar 24, 2016 at 11:50 AM, Colin O'Dell <colinodell@gmail.com>
> wrote:
> > […]
> I think you means !===, which is "not-identical assignment" (!== =)
>
> !==== is just *CRAZY TALK*
>
> -Sara

---

## #91920 — Alain Williams — 2016-03-24T19:13:55+00:00

URL: https://externals.io/message/91907#91920 · In reply to: #91917

> 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

---

## #91922 — Nikita Popov — 2016-03-24T19:16:58+00:00

URL: https://externals.io/message/91907#91922 · In reply to: #91918

> On Thu, Mar 24, 2016 at 11:50 AM, Colin O'Dell <colinodell@gmail.com>
> wrote:
> > […]
> 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

---

## #91923 — Mutlu Kocak — 2016-03-24T19:42:39+00:00

URL: https://externals.io/message/91907#91923 · In reply to: #91922

he is trolling :)



> On Thu, Mar 24, 2016 at 8:05 PM, Sara Golemon <pollita@php.net
> <javascript:;>> wrote:
>
> > […]
> <javascript:;>>
> > […]
>
> 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

---

## #91924 — James Titcumb — 2016-03-24T20:12:11+00:00

URL: https://externals.io/message/91907#91924 · In reply to: #91923

>
> 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.

---

## #91925 — Midori Kocak — 2016-03-24T20:16:50+00:00

URL: https://externals.io/message/91907#91925 · In reply to: #91924

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?


> 
> 
> 
> > […]
> 
> 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.

---

## #91931 — Alain Williams — 2016-03-24T22:08:15+00:00

URL: https://externals.io/message/91907#91931 · In reply to: #91925

> 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

---

## #91933 — Pierre Joye — 2016-03-25T02:25:10+00:00

URL: https://externals.io/message/91907#91933 · In reply to: #91907

Hi Nikita,


> 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

---

## #91936 — Yasuo Ohgaki — 2016-03-25T09:39:57+00:00

URL: https://externals.io/message/91907#91936 · In reply to: #91933

Hi all,


> 
> > […]
>
> I miserably fail to imagine any use case for this.
>
> > […]
>
> 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

---

## #91944 — Dmitry Stogov — 2016-03-25T12:38:45+00:00

URL: https://externals.io/message/91907#91944 · In reply to: #91907

I hope this is a joke.
Lets try not to reinvent Perl.

Thanks. Dmitry.
