Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:109941 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93825 invoked from network); 30 Apr 2020 10:16:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 30 Apr 2020 10:16:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 37B4F1804E2 for ; Thu, 30 Apr 2020 01:50:06 -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_40,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-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.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 ; Thu, 30 Apr 2020 01:50:05 -0700 (PDT) Received: by mail-wm1-f52.google.com with SMTP id u127so952620wmg.1 for ; Thu, 30 Apr 2020 01:50:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=KHNyyUAEG6XNQiESlvbnhjBtmcRx0WJ0NJbXi2Ag8cs=; b=TJCAFN3E/sleEetH2ehnRSSQx6GltxZoATfHDMT9Ro/G3sxOdKhTPUsDUnfNVwAoVZ yKmIPEclMovWeP69eAocncoVTumQXcBcdUrUggQDfTM8ogrUiXQawNWcSVNlsf9jFe2A IKx7pjilJjfGKZ3znQn23RVSsNeN8NQMMaj1T7NBS6+rtTXVKNc1/fmYIdv7iQUz6l5G o4eRXae1KTIs99Fs7v0MaPXa/raJOgQiQ1ljv0KW6+5KZZj+keVgITNU0wY+t755QRk3 dbPvKXm1FgxaUGxF1FEvPhkT7rhezQbEKccYDi5w9WyvjYcr4F8xqkuVjidjwDKHom/9 7d5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=KHNyyUAEG6XNQiESlvbnhjBtmcRx0WJ0NJbXi2Ag8cs=; b=BV7XJ37gem+gmJhNUvAyCG4tIF4H0HhkIRoiYUk1u7j2kEgO2SR5/n7MKyUG5Bh61m KiLC4EAh69pj8NvAIWkZ7cFDI4rzBKPb9xT9O5B12b1bJK9qZwgWcpJTFiU0ggoaz04Z snKEv5cS/v8sQOOYvL4cixR8Cp70JWZRKC10Mlfi+toNq2QFzpElDvQwnJPNk4y6r59o vwepvaSblt8U+I7O+DSsmS4e7Nxri/uYnriT94inpkjFLoqr3otMEaJtcx6mVtUQFEyP jAPqpUFnPRzrNvTNnBgy6hVF82JvlLBbY1oL+xaEbJBOWPz6zRyaFoybMH6jcxjDStdQ 5m+g== X-Gm-Message-State: AGi0PuZHmH3JjE6b+21H49tUrO4K2y2PU6dd39WskKqYYuxdnZF8XFZp swlE37C9EU8kd8N9UfRfWq6m4+YqNiO9sFZgV8iQ19njIH8= X-Google-Smtp-Source: APiQypITIE5e9fXEjzEeJtdlZGA9SmFFUoCzX9k3WR9pBaoyu+M5mSiH0BBoq7iTrHQ9neE7cCDb51QYHDSw5NTGnFg= X-Received: by 2002:a05:600c:29c2:: with SMTP id s2mr1738426wmd.111.1588236602730; Thu, 30 Apr 2020 01:50:02 -0700 (PDT) MIME-Version: 1.0 Date: Thu, 30 Apr 2020 11:49:51 +0300 Message-ID: To: php internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] [VOTE] match expression From: someniatko@gmail.com (=?UTF-8?B?0JjQu9GM0Y8g0KHQvtC80L7Qsg==?=) Hi! I am quite new to the internals list, but wanted to say a word, to maybe lit some light on the discussion, for you to be able to look at it from slightly another angle. I have noticed this whole thread arguing whether it is required or not to support `match` keyword in an if-else-ish control-flow manner: in other words, support not only expressions in the `match` branches, but also arbitrary statements. As we know, each PHP expression can be used as a statement. We also know that large subset of practically used statements (function call, variable assignment) can be implemented in expression form. This subset also tends to enlarge: recently throwing an exception became expressible in expression form. This means we can write code like this: ``` match($state) { State::VALID => processFurther(), State::PENDING => $isPending = true, State::INVALID => throw new \RuntimeException(), }; ``` IMO this covers vast majority of use-cases of the PHP statements. The cases which are not covered are: 1) statements which cannot be expressed as expressions: `echo`, `unset`. 2) control flow which requires usage of more than one statement, e.g. assigning two variables, or calling two functions with void return type one after another one etc. I would like to emphasize that this problem is the same as short closures problem, and should be treated at the same time. Problem no. 1 could be solved by allowing statements like `unset` to be used in expression form, if it's feasible. Problem no. 2 could be addressed by allowing "complex" expressions consisting of, potentially, few statements, language-wide, solving the issue both for short closures and for `match`, if it is really needed though. Anyway it is possible to use in-place old-school closure as a temporary workaround. > 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. IMO a good language should enforce better quality. Especially when we talk about new language constructs. Short closures already enforce SRP, at least in closures world. Also, those people who would benefit from less boilerplate which match in expression-only form provides, are usually the people who care about code quality. Those who you mention as "average code quality" would not bother with new syntax at all and would still prefer old-school switch to do whatever level of entanglement they had used to. If, though, you insist on match to completely replace old switch, as well as short closures to replace traditional ones, you may want to consider to solve "complex expression" problem once for both of them, and move this out of scope of this RFC. This will allow for gradual improvement of the language, from which both parties will benefit: those who want to write clean code (which is usually split up in functions such that match can be used straight away with only one expression per arm), and those who use complex logic in switches - will be able to do the same in match, but later, when "complex expressions" are implemented. someniatko