[VOTE] Combined Comparison (Spaceship) Operator

php.internals

Andrew Faulds

11 years ago
Hi everyone, Since it's been two weeks and there are no remaining issues (aside from the lack of a language specification patch - but that can be done later), I'm opening voting on this RFC. Voting starts today (2015-02-02) and ends in two weeks' time (2015-02-16). As this adds to the PHP language (and hence affects the PHP language specification) a 2/3 majority is required for acceptance. The RFC, which contains the voting widget, can be found here: https://wiki.php.net/rfc/combined-comparison-operator Thanks!
-- Andrea Faulds http://ajf.me/

Nikita Popov

11 years ago
On Mon, Feb 2, 2015 at 1:06 PM, Andrea Faulds <ajf@ajf.me> wrote:
> Hi everyone, > > Since it's been two weeks and there are no remaining issues (aside from > the lack of a language specification patch - but that can be done later), > I'm opening voting on this RFC. > > Voting starts today (2015-02-02) and ends in two weeks' time (2015-02-16). > As this adds to the PHP language (and hence affects the PHP language > specification) a 2/3 majority is required for acceptance. > > The RFC, which contains the voting widget, can be found here: > https://wiki.php.net/rfc/combined-comparison-operator > > Thanks! >
I've voted -1 because I think this should be a function and not an operator. compare($a, $b) is more obvious than $a <=> $b and it's not like writing comparison functions is such a super common use case that it needs the extra brevity of an operator. A function can furthermore be used as a callback, while an operator requires a wrapping closure. Nikita

Markus Fischer

11 years ago
On 02.02.15 14:49, Nikita Popov wrote:
> I've voted -1 because I think this should be a function and not an > operator. compare($a, $b) is more obvious than $a <=> $b and it's not like > writing comparison functions is such a super common use case that it needs > the extra brevity of an operator. A function can furthermore be used as a > callback, while an operator requires a wrapping closure.
I support what Nikita said, but it doesn't influence my vote; I see them separate. Btw, I would be hesitant to introduce such a common name 'compare'. thanks, - Markus

Andrew Faulds

11 years ago
Hey Nikita,
> On 2 Feb 2015, at 13:49, Nikita Popov <nikita.ppv@gmail.com> wrote: > > I've voted -1 because I think this should be a function and not an operator. compare($a, $b) is more obvious than $a <=> $b and it's not like writing comparison functions is such a super common use case that it needs the extra brevity of an operator. A function can furthermore be used as a callback, while an operator requires a wrapping closure.
There’s no actual use for the bare comparison operation as a callback, though: usort($foo, ‘compare’); would just be a slow version of sort($foo); I agree that having it be available as a function might be useful in some cases, but this is also true of most operators. I think it would be better to add some means of obtaining a closure for PHP’s operators, however. Thanks.
-- Andrea Faulds http://ajf.me/

Levi Morrison

11 years ago
On Mon, Feb 2, 2015 at 8:27 AM, Andrea Faulds <ajf@ajf.me> wrote:
> Hey Nikita, > >> On 2 Feb 2015, at 13:49, Nikita Popov <nikita.ppv@gmail.com> wrote: >> >> I've voted -1 because I think this should be a function and not an operator. compare($a, $b) is more obvious than $a <=> $b and it's not like writing comparison functions is such a super common use case that it needs the extra brevity of an operator. A function can furthermore be used as a callback, while an operator requires a wrapping closure. > > There’s no actual use for the bare comparison operation as a callback, though: usort($foo, ‘compare’); would just be a slow version of sort($foo);
For this particular use-case you are correct, but usually I use custom callbacks for something more interesting, such as comparing one value and then comparing another based on the result. Perhaps the callback is higher-level: function (callable $comparator) { return function ($selector) use ($comparator) { return function ($a, $b) use($selector, $comparator) { return $comparator($selector($a), $selector($b)); }; }; } Maybe I'm the only one doing stuff like this, but it's not uncommon for me ^^

Nikita Popov

11 years ago
On Mon, Feb 2, 2015 at 4:27 PM, Andrea Faulds <ajf@ajf.me> wrote:
> Hey Nikita, > > > On 2 Feb 2015, at 13:49, Nikita Popov <nikita.ppv@gmail.com> wrote: > > > > I've voted -1 because I think this should be a function and not an > operator. compare($a, $b) is more obvious than $a <=> $b and it's not like > writing comparison functions is such a super common use case that it needs > the extra brevity of an operator. A function can furthermore be used as a > callback, while an operator requires a wrapping closure. > > There’s no actual use for the bare comparison operation as a callback, > though: usort($foo, ‘compare’); would just be a slow version of sort($foo); >
It may not be applicable to a direct sort() call, but it's useful for higher level APIs. With a function you can create APIs of the form `function foo(..., $comparator = 'compare') { ... }`, which will default to the "standard" comparison function without having to specially handle it all over the place. Nikita

Andrew Faulds

11 years ago
Hey Nikita,
> On 2 Feb 2015, at 16:32, Nikita Popov <nikita.ppv@gmail.com> wrote: > > On Mon, Feb 2, 2015 at 4:27 PM, Andrea Faulds <ajf@ajf.me> wrote: > Hey Nikita, > > > On 2 Feb 2015, at 13:49, Nikita Popov <nikita.ppv@gmail.com> wrote: > > > > I've voted -1 because I think this should be a function and not an operator. compare($a, $b) is more obvious than $a <=> $b and it's not like writing comparison functions is such a super common use case that it needs the extra brevity of an operator. A function can furthermore be used as a callback, while an operator requires a wrapping closure. > > There’s no actual use for the bare comparison operation as a callback, though: usort($foo, ‘compare’); would just be a slow version of sort($foo); > > It may not be applicable to a direct sort() call, but it's useful for higher level APIs. With a function you can create APIs of the form `function foo(..., $comparator = 'compare') { ... }`, which will default to the "standard" comparison function without having to specially handle it all over the place.
Yes, that’s true. I’d previously suggested adding a function to get a closure of an operator. But actually, perhaps we should just follow PHP’s traditional string typing of callables, and make ‘+’, ‘-‘, ‘<‘, ‘<=>’ etc. be valid callables? Thus: function doesThing($a, $b, callable $callback = ‘+’) { return $callback($a, $b); } doesThing(1, 2); // 3 Thoughts? (I realise this is slightly OT.)
-- Andrea Faulds http://ajf.me/

Levi Morrison

11 years ago
> Since it's been two weeks and there are no remaining issues (aside from the lack of a language specification patch - but that can be done later), I'm opening voting on this RFC.
I just noticed that you kept T_SPACESHIP; while that is fun I don't think it is appropriate. It is a common name for the operator, but there are other common names as well. Even though I am undecided on the merit of the RFC I am voting "no" because of this detail.

Pierre Joye

11 years ago
On Mon, Feb 2, 2015 at 11:44 PM, Levi Morrison <levim@php.net> wrote:
>> Since it's been two weeks and there are no remaining issues (aside from the lack of a language specification patch - but that can be done later), I'm opening voting on this RFC. > > I just noticed that you kept T_SPACESHIP; while that is fun I don't > think it is appropriate. It is a common name for the operator, but > there are other common names as well. Even though I am undecided on > the merit of the RFC I am voting "no" because of this detail.
Google "spaceship operator", now imagine adding "php", reconsider :) It is not about funny but easiness to find it and what it is all about.
-- Pierre @pierrejoye | http://www.libgd.org

Pavel Kouřil

11 years ago
Hello, I personally would use spaceship operator often, but only if PHP had operator overloading for classes. So I hope it will pass and operator overloading will pass someday as well (but operator overloading would probably require method overloading first and that's a thing you guys oppose, right?). Regards Pavel Kouril

Stas Malyshev

11 years ago
Hi!
> I personally would use spaceship operator often, but only if PHP had > operator overloading for classes. So I hope it will pass and operator
PHP has operator overloading for classes, but just for internal ones. See: https://wiki.php.net/rfc/operator_overloading_gmp For userspace ones, the feeling is unlimited overloading would be a bit too chaotic.
-- Stas Malyshev smalyshev@gmail.com

Pavel Kouřil

11 years ago
On Mon, Feb 2, 2015 at 11:50 PM, Stanislav Malyshev <smalyshev@gmail.com> wrote:
> Hi! > >> I personally would use spaceship operator often, but only if PHP had >> operator overloading for classes. So I hope it will pass and operator > > PHP has operator overloading for classes, but just for internal ones. > See: https://wiki.php.net/rfc/operator_overloading_gmp > > For userspace ones, the feeling is unlimited overloading would be a bit > too chaotic. > -- > Stas Malyshev > smalyshev@gmail.com
Hello, yeah, I meant userspace operator overloading. I don't think it would be chaotic - for instance C# allows it and it comes in handy sometimes and is not chaotic at all.

Pascal MARTIN

11 years ago
Le 02/02/2015 13:06, Andrea Faulds a écrit :
> The RFC, which contains the voting widget, can be found here: https://wiki.php.net/rfc/combined-comparison-operator > > Thanks!
Hi, Discussing this RFC with other people of AFUP, we would be +1. Basically: adding such an operator would make things much easier when it comes to writing comparison functions. (Even though the RFC has been withdrawn, I thought posting this could help, if anyone wishes to keep working on it)
-- Pascal MARTIN, AFUP - French UG http://php-internals.afup.org/

Stas Malyshev

11 years ago
Hi! Since Andrea has withdrawn the spaceship operator RFC (https://wiki.php.net/rfc/combined-comparison-operator), I'd like to resurrect it. Looks like by vote results (with 1 day of official vote left) it was clearly passing, so are there any objections to treating it as passed? If not, I'll treat it as such and do the merging as soon as I have time. Thanks,
-- Stas Malyshev smalyshev@gmail.com

Yasuo Ohgaki

11 years ago
Hi Stas, On Mon, Feb 16, 2015 at 2:20 PM, Stanislav Malyshev <smalyshev@gmail.com> wrote:
> Since Andrea has withdrawn the spaceship operator RFC > (https://wiki.php.net/rfc/combined-comparison-operator), I'd like to > resurrect it. Looks like by vote results (with 1 day of official vote > left) it was clearly passing, so are there any objections to treating it > as passed? If not, I'll treat it as such and do the merging as soon as I > have time. >
What happen to her/RFC? I know it's very frustrating if people oppose RFC. People just have different views/understandings. I hope she will be back soon. Anyway, +1 Regards,
-- Yasuo Ohgaki yohgaki@ohgaki.net

François Laupretre

11 years ago
Hi Stas,
> De : Stanislav Malyshev > > > Since Andrea has withdrawn the spaceship operator RFC > > (https://wiki.php.net/rfc/combined-comparison-operator), I'd like to > > resurrect it. Looks like by vote results (with 1 day of official vote > > left) it was clearly passing, so are there any objections to treating it > > as passed? If not, I'll treat it as such and do the merging as soon as I > > have time.
Reopen it for one day. It's quite crazy but it does not create a precedent. Andrea said she gave the RFC to anyone wishing to go on with it. If you officially take over the RFC, you are the owner, you can do that. François

Stas Malyshev

11 years ago
Hi!
> Reopen it for one day. It's quite crazy but it does not create a > precedent. Andrea said she gave the RFC to anyone wishing to go on > with it. If you officially take over the RFC, you are the owner, you > can do that.
OK, I've put it back to vote for a day. Will close it tomorrow.
-- Stas Malyshev smalyshev@gmail.com

Pascal MARTIN

11 years ago
Le 16/02/2015 11:58, Stanislav Malyshev a écrit :
> Hi! > >> Reopen it for one day. It's quite crazy but it does not create a >> precedent. Andrea said she gave the RFC to anyone wishing to go on >> with it. If you officially take over the RFC, you are the owner, you >> can do that. > > OK, I've put it back to vote for a day. Will close it tomorrow. >
Hi, Thanks for reviving this!
-- Pascal MARTIN, AFUP - French UG http://php-internals.afup.org/

Matteo Beccati

11 years ago
Hi Stas, On 16/02/2015 06:20, Stanislav Malyshev wrote:
> Since Andrea has withdrawn the spaceship operator RFC > (https://wiki.php.net/rfc/combined-comparison-operator), I'd like to > resurrect it. Looks like by vote results (with 1 day of official vote > left) it was clearly passing, so are there any objections to treating it > as passed? If not, I'll treat it as such and do the merging as soon as I > have time.
Andrea quitting is very sad news. About your question, I don't know... treating a cancelled voting result as if it wasn't might be setting a weird precedent, even though it was so close to the end and had an overwhelming majority. Cheers
-- Matteo Beccati Development & Consulting - http://www.beccati.com/

Stas Malyshev

11 years ago
Hi!
> About your question, I don't know... treating a cancelled voting result > as if it wasn't might be setting a weird precedent, even though it was > so close to the end and had an overwhelming majority.
The only reason it was cancelled because of Andrea quitting, and with one day left result is pretty clear. Running the same vote again with 4:1 for sounds pointless to me. If it was a close one then fine, but it's not really close. If anybody would want to abuse this in the future as a precedent for gaming the system, we'll deal with it then appropriately, I'm sure.
-- Stas Malyshev smalyshev@gmail.com

Matteo Beccati

11 years ago
Hi Stas!
>> About your question, I don't know... treating a cancelled voting result >> as if it wasn't might be setting a weird precedent, even though it was >> so close to the end and had an overwhelming majority. > > The only reason it was cancelled because of Andrea quitting, and with > one day left result is pretty clear. Running the same vote again with > 4:1 for sounds pointless to me. If it was a close one then fine, but > it's not really close. > If anybody would want to abuse this in the future as a precedent for > gaming the system, we'll deal with it then appropriately, I'm sure.
A bit of flexibility surely doesn't hurt, indeed. I just thought it was worth to raise it. I personally have no objections. Cheers
-- Matteo Beccati Development & Consulting - http://www.beccati.com/

Andrew Faulds

11 years ago
Hi Stas,
> On 16 Feb 2015, at 05:20, Stanislav Malyshev <smalyshev@gmail.com> wrote: > > Since Andrea has withdrawn the spaceship operator RFC > (https://wiki.php.net/rfc/combined-comparison-operator), I'd like to > resurrect it. Looks like by vote results (with 1 day of official vote > left) it was clearly passing, so are there any objections to treating it > as passed? If not, I'll treat it as such and do the merging as soon as I > have time.
I’m fine with that (though I’d already given permission in the “I quit.” email). I assume Davey’s fine with it as well, though you should probably check with him just to be sure. One thing of note is that I didn’t write a language specification patch. If you’re to pick it up, I guess you’d have to do that at some point, sorry about that. Thanks.
-- Andrea Faulds http://ajf.me/

Stas Malyshev

11 years ago
Hi!
> One thing of note is that I didn’t write a language specification > patch. If you’re to pick it up, I guess you’d have to do that at some > point, sorry about that.
No problem, I'll take care of it, thanks for the reminder.
-- Stas Malyshev smalyshev@gmail.com