Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109868 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15786 invoked from network); 28 Apr 2020 10:15:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Apr 2020 10:15:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id EF9F1180088 for ; Tue, 28 Apr 2020 01:48:46 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) (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 ; Tue, 28 Apr 2020 01:48:46 -0700 (PDT) Received: by mail-lf1-f52.google.com with SMTP id t11so16179280lfe.4 for ; Tue, 28 Apr 2020 01:48:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=P3xrS39t6YO7EuIKpJwkbAT9n7eJEXZAHj/n6pHUY1c=; b=IhrD+yZHuG41I7JtfCofGaSo+qLcM/JmwzOunY7CUvm/Wq/v+g9PmVj2MyzLrno6uk Y3YDKcZ98sF1qHbyqnVBX01eH/+cdZa6NgNMrKhNb33L4dpeqSUvhFXw/WjYVZUlL5yc AlPcJ8SeSzRNssvyNWZ0dv2UVU6V5xrmsUpwSC+DMGKj23QfaFy52bON0tjZEXHZo26t vOrATHOuymMxldjvL20OO+mfl0tstaA0CUq7c8ZC9u3irK45sXeFgHZf3c6jFMBtQoFe rFpwRICzde0pcZIKn17As3ZclS/aRSy+ydQbQz1gOKagGqnqfCIfEuwKtyhe6XYTzLqJ V1wg== 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=P3xrS39t6YO7EuIKpJwkbAT9n7eJEXZAHj/n6pHUY1c=; b=saoPZytSFtDgRhdVkQ1NNaVHw4lKU5jU+pmFDZ7XjAB9INK8jStzU1KKMpd5PXsX/P Djei7kWioVQol0iG6rJ7c8fKt8TAdJhs1WpXGggVa+TweKTc3VqryBzII/iA7t+kyDoH euHTaMdc9PdFSdfyLMhPq6oTYH2RKSLnHgeLuWThHcfWtku8zqqyW4OoPZh/80WyZaq/ ShyTka5n4q4duCFfaioUxNY2J8B3DUSb6r+tyrz+xQ4TY5NG/vS3TH7uN2MoRteA2f5u ICHPJpm/2Ta5P57fps1/ygMte8wPOC5k2P7rias8QO1VTUMDu30PQCUA/T1ZFVIiySDJ cxYA== X-Gm-Message-State: AGi0Pubvxa8GSKgA8abW32fTvyARaYDZ21xDXq3JUrP8y4SUZg4md83C bNKLMSHQWVF2UsmQxQzBnS0Wgyr3XJesk/yNiIqpdj1GER6SNQ== X-Google-Smtp-Source: APiQypJ/BdjwrpfSbDmXjuPEXbYmMazORxeOujK97vnkxHY+fYEMk36O4xJ3ch3FbJ4niy8J8fivrqcuBK/IAnto2Y0= X-Received: by 2002:a19:c7d8:: with SMTP id x207mr18085297lff.190.1588063724838; Tue, 28 Apr 2020 01:48:44 -0700 (PDT) MIME-Version: 1.0 References: <5ea6e4b0.1c69fb81.cf3ee.2bbfSMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: <5ea6e4b0.1c69fb81.cf3ee.2bbfSMTPIN_ADDED_MISSING@mx.google.com> Date: Tue, 28 Apr 2020 10:48:28 +0200 Message-ID: To: Andrea Faulds Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000003324a505a455e662" Subject: Re: [PHP-DEV] [VOTE] match expression From: nikita.ppv@gmail.com (Nikita Popov) --0000000000003324a505a455e662 Content-Type: text/plain; charset="UTF-8" On Mon, Apr 27, 2020 at 3:57 PM Andrea Faulds wrote: > Hi, > > I share Dan's reasons for voting against. I don't think things should go > to a vote before the dust has settled. > > Regards, > Andrea Faulds > Similar sentiment here. I don't think the concept has been explored sufficiently. Many people in the voting thread are calling for supporting match expressions only (without support for either statement form, or support for block expressions). The RFC motivates the match construct as an improved replacement for switch, which is type-safe, exhaustive and has no fallthrough gotchas. If we limit match to returning simple expressions only, is it still a viable replacement for switch? I've looked at a sample of ~50 switches randomly picked from popular composer packages, the list can be found here: https://gist.github.com/nikic/fc225f02ea76c02e669a598cfc471b83 I've classified these according to whether the switches could be rewritten as a match if it only supports expression, but not statement form. What I was looking for here was the ability to more or less directly translate, without having to do major refactoring first. Results: 2595: no (only with block expression support) 8337: no (only with block expression support) 2115: no 7109: no (only with block expression support) 6564: no 7786: no (only by returning a pair, and only realistic with block expression support) 2609: yes 7450: no (only by returning a triple, and only with block expression support) 5338: no 567: no 3376: yes (but weird stylistically) 2850: no 2635: yes 61: no 6562: no 2354: yes 522: no 4972: yes 8179: no 6080: yes 5997: yes 6758: yes 6718: no (only with block expression support) 1451: maybe 9152: yes 4192: no 4099: no 6773: yes 2727: yes (but weird stylistically) 6779: yes 2710: no 149: yes 7501: no 1197: no (only with block expression support) 6845: yes 6610: no 1088: yes (but weird stylistically) 2806: yes 3393: no 8361: no (only by returning a pair, and only with block expression support) 4473: no 8543: no 8792: no (only with block expression support, maybe) 8776: no 1165: yes 8388: yes 8294: no 3840: yes 3587: yes 6428: (empty switch) 8324: no 1280: no 2023: yes 8084: no (maybe with block expression support) Of the switches I looked at, 31 cannot use match in single-expression form, while 21 can. Is match intended as a replacement for switch? Or is intended to replace the ternary operator? Do we want people to be able to convert switches to matches without much hassle, or is this only intended for a specific subset? I'm not quite clear on what "match" is intended to be, and I think different people in this discussion have rather different views on this. Regards, Nikita --0000000000003324a505a455e662--