Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109870 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 28174 invoked from network); 28 Apr 2020 11:45:47 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 28 Apr 2020 11:45:47 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 189581804C4 for ; Tue, 28 Apr 2020 03:18:55 -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=-0.2 required=5.0 tests=BAYES_20,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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-yb1-f175.google.com (mail-yb1-f175.google.com [209.85.219.175]) (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 03:18:54 -0700 (PDT) Received: by mail-yb1-f175.google.com with SMTP id b17so11110821ybq.13 for ; Tue, 28 Apr 2020 03:18:54 -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; bh=syDiVFqZLdORQ4Wht9nEOjNLCbgnThIDcvuDzRrxlTQ=; b=SuyZzUuxfHtP+ASLmvZA1JPSHS1/z9ARjPWrmRSVhVDnrWDCxCNrKQXsPtELfQaY+t okh7+ciAAMcZVgIIOzGcPi2mroaf3sATpk92kZr5RzMzTc+LMUPu1pNf3SpYF+h1qaNE 0gvdvqGx3AJHaQiB8KSpBPSkCbP6OR+OyZCzkEnp+wPiVTWLUs/S7FBkpWyMULGSt1jc he5aJDDKgKb+h+iIAnfVseEwKhdyxEGGSKV07c9/K9B3STwGYdOD2YPkE4lB12N1TtNe XfUELNMyWMK2t5os0Muv/exuNbxVYwf82eeD/OzYbp1Hq0cVicmFZCL9ri+oyoP/7g1J vq8g== 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; bh=syDiVFqZLdORQ4Wht9nEOjNLCbgnThIDcvuDzRrxlTQ=; b=SPyIH1B6vBtfc39eMWsB/PXtxNAyR1GA3wRtV4imULMZP13qoXyjSY5NpK0Biqtm7b ThRX/GkH2cRFL7nX/vD4hqB5UelIY/xusffKTfYdNXyEMB73OXw51F2aMe6I7Am1bbJF E8tOJ39bFFIjK3JjXYkTHik/j3mEJrqob1LauD7K3qAhTnAShA/sJy/DOunWQyq21/xk JFWewHsInsuRwDvRKE9m6CCp95ZIojfiKXRd5vD7mClQKTxKjaKmXw6uPAKra9IaJIJ4 xMUH0+mqH4raQptdzw0vjGyiKwb3DE5BgB49hVV/WE+4T/GZT49deOFdQCj3WjMMUB/e qf/w== X-Gm-Message-State: AGi0PuYc6QsvsJahTff+WJXsjd8dAXFfMqKE4XQBqau+2I5cPTpbPxKU WzRRFHe2Q9g65bqUk45rRQNcQQuZezRvFvpPQAnc/SYh X-Google-Smtp-Source: APiQypLwtm0f+kOGzGLuape8l3w7FR9kji792XeTLfvwO/sMlgfbOkHVeb3Ki7dl5qpSyNYqzdLZYVR1DkS5gvlCXac= X-Received: by 2002:a25:b8c1:: with SMTP id g1mr43698175ybm.411.1588069133547; Tue, 28 Apr 2020 03:18:53 -0700 (PDT) MIME-Version: 1.0 References: <5ea6e4b0.1c69fb81.cf3ee.2bbfSMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: Date: Tue, 28 Apr 2020 12:18:42 +0200 Message-ID: To: PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [VOTE] match expression From: tovilo.ilija@gmail.com (Ilija Tovilo) Hi Nikita Thank you for your analysis. That's something I should've done as part of the RFC. I can only share my personal motivation for creating this RFC. Some people will disagree. > Is match intended as a replacement for switch? To me, match is primarily a switch alternative with safer semantics. While it is very nice that match evaluates to the executed arm I think statement matches would be more common and more useful. Your analysis seems to align with that. > If we limit match to returning simple expressions > only, is it still a viable replacement for switch? I don't think so. Of course, some people might argue that the switch is fine and doesn't need a replacement which is an entirely valid viewpoint. However, that would directly contradict most of the arguments made in the RFC. If the switch is fine adding another alternative with different semantics is questionable. If the issues listed in the RFC are valid IMO this RFC only makes sense supporting blocks. > Of the switches I looked at, 31 cannot use match in single-expression form, > while 21 can. I think that sums it up nicely. Let's also remember that these are popular, well maintained repositories and probably don't reflect the average code quality very well. Let me also address Rowans comment: > Why does it need to *replace* anything? Introducing switch to a language > isn't usually considered a replacement for if-elseif-else, even though the > usage overlaps heavily. The if statement doesn't have (most of) the issues stated in the RFC. Match is a direct response to the flaws of the switch. Without blocks match won't actually be usable in most of these cases and you'll be stuck with switch and its flaws. Again, you can argue the switch doesn't have flaws but then the whole RFC doesn't make any sense. > for the control-flow statement, it feels awkward and not in > keeping with the rest of the language. If they were separate proposals, the > statement would probably end up looking very different. Can you elaborate? If I made a proposal exclusively for match statements the syntax would be exactly equivalent. Ilija