Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108842 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 90991 invoked from network); 4 Mar 2020 18:58:00 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Mar 2020 18:58:00 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 988EF1804E4 for ; Wed, 4 Mar 2020 09:17:25 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: * X-Spam-Status: No, score=1.4 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 4 Mar 2020 09:17:25 -0800 (PST) Received: by mail-qt1-f170.google.com with SMTP id o10so1927087qtr.7 for ; Wed, 04 Mar 2020 09:17:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=SiuKv5elyC6upeArgIstvabrUnAeF2xM4rc41H03deg=; b=WEv5GLp4PgqcxN5UN/8I/5RteDQJ6vWH5Z0/R01ih3qxUKZpYnrzVYn+FFyyyWRfTs dFK1c8gvGswogZcjmAm8RZtY9ulopxJkFKDc80PmoDjXpvwWxik0MBtEC/mtHd5Pq08W pSv809udrTPTI3PZ401s25k75H20n9BTAZOyHrZZOfh2J1RduoyPNHr/ckgWDJulANGp 1tn5uAkdPBiJgWH+lYvkffK0x5iEEirIwR/6AMquZNzY7Hy7ywy7ZlK5tzhISUFqx+BI NNF79w2YTHTaQTg8/+DnUwLErFJ459LLurE7v6RslrBj6XOqyiiYNvGVIgFWZIYa/uMn E7NA== X-Gm-Message-State: ANhLgQ3InyUzzK/oqYpOwOdesIu6xze3U3ZluVrZERXLef6o8gYO4ygD TIcvI1ExpXhHNyppXP6NVcIUdJszmn25iFrYSoOrVw== X-Google-Smtp-Source: ADFU+vuy8zE6UQdq7IRhDQ0kC4JWmkC5QcL4zmjHaLBrjtHDCeJXuZAgEcd5rBhf2ckqCveCRVXZBm9myNTf2yYoAQM= X-Received: by 2002:aed:204d:: with SMTP id 71mr3469825qta.116.1583342242091; Wed, 04 Mar 2020 09:17:22 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 4 Mar 2020 11:16:59 -0600 Message-ID: To: Nikita Popov Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000e5e9ca05a00a979a" Subject: Re: [PHP-DEV] Make sorting stable From: pollita@php.net (Sara Golemon) --000000000000e5e9ca05a00a979a Content-Type: text/plain; charset="UTF-8" On Wed, Mar 4, 2020 at 10:42 AM Nikita Popov wrote: > The only issue I ran into is that this change has a negative impact on code > using illegal comparison callbacks like this: > > usort($array, function($a, $b) { > return $a > $b; > }); > > Let's define what "negative impact" means in this regard. Is it that one still winds up with an essentially sorted array, but hitherto "stable appering" output is now stable in a different way? Or is the result actually just NOT sorted in a way that a reasonable user would consider correct (e.g. 5 sorted before "3")? If it's the former, then I'm generally disinclined to be concerned about the breakage. We never made a promise about comparison equality resolution, so moving to making a promise about it isn't violating anything. > This kind of incorrect code will break under the proposed implementation, > because we will now compare by original position if the comparison function > reports equality. Because the comparator reports equality inconsistently > (it says that $a == $b, but $b != $a), the sort results are also > inconsistent. > > I read this user-space comparator as saying that values are never equal. Sometimes $a > $b and $b > $a are both true, which is terrible. But if they never report equality, then position sorting should never come into play. > What do people think about this? Is there interest in making sorting > stable? Is it okay to break code using illegal comparison callbacks? > > Generally +1, just curious about what breaks and how. -Sara --000000000000e5e9ca05a00a979a--