Newsgroups: php.internals
Path: news.php.net
Xref: news.php.net php.internals:110267
Return-Path: <me@daveyshafik.com>
Delivered-To: mailing list internals@lists.php.net
Received: (qmail 75109 invoked from network); 23 May 2020 08:51:39 -0000
Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5)
  by pb1.pair.com with SMTP; 23 May 2020 08:51:39 -0000
Received: from php-smtp4.php.net (localhost [127.0.0.1])
	by php-smtp4.php.net (Postfix) with ESMTP id EC8891804C3
	for <internals@lists.php.net>; Sat, 23 May 2020 00:31:01 -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=-1.6 required=5.0 tests=BAYES_00,
	HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,
	RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE 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: <me@daveyshafik.com>
Received: from mail-yb1-f173.google.com (mail-yb1-f173.google.com [209.85.219.173])
	(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 <internals@lists.php.net>; Sat, 23 May 2020 00:31:01 -0700 (PDT)
Received: by mail-yb1-f173.google.com with SMTP id g79so5803752ybf.0
        for <internals@lists.php.net>; Sat, 23 May 2020 00:31:01 -0700 (PDT)
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=CB39n5dBc3hbpBKmGrNNNOkziV4JjSgAuo9O3sTA2QQ=;
        b=AfvtQ3+8KD+3ei/b+teuOfYUP2JP29+XoPayDMd5MuPdlq1cqOw8vABM6T4L1gREHH
         sl2xbIQzN8SVa1oU+0HEg3wAqEbiejPmJPAbOPT+1PvEs+4vr8cypkD0+KNu44d4yrSP
         r+7M8Wi9l+k/ZyKxJSgHOAVu7YSUv4pWkzttAY3W/kCCtb5vNmwA+cSmRSIzx0bwhjSX
         sOfEmZqxA3noYtXvGoeN27tlkm2RWZLVb6hffKJ5pfAX+gWcrkaz6VFR07Zowf2uH+bG
         FR4YiDQCNiayyBJy6jYhXHGaegj+LhmxpJYUUftzTxf4+wRyFwzs3csefd4xhSEH/ueX
         pfHg==
X-Gm-Message-State: AOAM53008fOVc/dZG/c6rKn0PTzZxzD7deq5Xccn8i049B7U224oxBjP
	Gpf1bItYlEW2EaykUphARLQY1cYxpwJLrFx7MSOcFA==
X-Google-Smtp-Source: ABdhPJy5qYj7UXkYiU1JYL/O7Z2G/7mk6nGZ9NnBWqw6UIEhNX48JAJ7YsvbyR/UBs0Fp2wmAYPO6Tw0qrZPyfBXj88=
X-Received: by 2002:a05:6902:688:: with SMTP id i8mr28532164ybt.21.1590219060796;
 Sat, 23 May 2020 00:31:00 -0700 (PDT)
MIME-Version: 1.0
References: <CAPyj-LB7jSiv+7DheaYpEcZXbjeJ9OMsRUTMOofnWbH4LyOQhA@mail.gmail.com>
In-Reply-To: <CAPyj-LB7jSiv+7DheaYpEcZXbjeJ9OMsRUTMOofnWbH4LyOQhA@mail.gmail.com>
Date: Sat, 23 May 2020 00:30:50 -0700
Message-ID: <CANaX5negML1uV=GtSc7zkkHPBfbpb6xa721USW31+_-4X-onfQ@mail.gmail.com>
To: Ilija Tovilo <tovilo.ilija@gmail.com>
Cc: PHP internals <internals@lists.php.net>
Content-Type: multipart/alternative; boundary="0000000000003beaf005a64bba5e"
Subject: Re: [PHP-DEV] [RFC][DISCUSSION] Match expression v2
From: davey@php.net (Davey Shafik)

--0000000000003beaf005a64bba5e
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Fri, May 22, 2020 at 4:09 AM Ilija Tovilo <tovilo.ilija@gmail.com> wrote=
:

> Hi internals
>
> I'd like to announce the match expression v2 RFC:
> https://wiki.php.net/rfc/match_expression_v2
>
> The goal of the new draft is to be as simple and uncontroversial as
> possible. It differs from v1 in the following ways:
>
> * Blocks were removed
> * Secondary votes were removed
>     * optional semicolon
>     * omitting `(true)`
> * Unimportant details were removed (e.g. examples for future scope)
>
> You can look at the diff here:
> https://github.com/iluuu1994/match-expression-rfc/pull/8/files
>
> I will also leave the discussion period open for longer as that too
> was one of the primary criticisms.
>
> As mentioned by Kalle:
>
> > Resurrecting rejected RFCs have a "cooldown" of 6 months:
> > https://wiki.php.net/rfc/voting#resurrecting_rejected_proposals
>
> That is, unless:
>
> > The author(s) make substantial changes to the proposal. While it's
> > impossible to put clear definitions on what constitutes 'substantial'
> > changes, they should be material enough so that they'll significantly
> > affect the outcome of another vote.
>
> Given that many people have said without blocks they'd vote yes I'd
> say this is the case here. Let me know if you don't agree.
>
> Ilija
>

With these simplifications, I'm not entirely sure there is enough value
here if the Conditional Return, Break, and Continue Statements RFC is
passed. This could be written with the slightly more ugly, but serviceable:

So this:
$statement =3D match ($this->lexer->lookahead['type']) {
    Lexer::T_SELECT =3D> $this->SelectStatement(),
    Lexer::T_UPDATE =3D> $this->UpdateStatement(),
    Lexer::T_DELETE =3D> $this->DeleteStatement(),
    default =3D> $this->syntaxError('SELECT, UPDATE or DELETE'),
};

could be expressed as:

echo (function($match) {
    return $this->SelectStatement() if ($match =3D=3D=3D Lexer::T_SELECT);
    return $this->UpdateStatement() if ($match =3D=3D=3D Lexer::T_UPDATE);
    return $this->DeleteStatement() if ($match =3D=3D=3D Lexer::T_DELETE);
    return $this->syntaxError('SELECT, UPDATE or DELETE');
})($this->lexer->lookahead['type']);

I mean, ultimately, it's equivalent to:

echo (function($match) {
    if ($match =3D=3D=3D Lexer::T_SELECT) {
        return $this->SelectStatement()
    }
    if ($match =3D=3D=3D Lexer::T_UPDATE) {
        return $this->UpdateStatement()
    }
    if ($match =3D=3D=3D Lexer::T_DELETE) {
        return $this->SelectStatement()
    }
    return $this->syntaxError('SELECT, UPDATE or DELETE');
})($this->lexer->lookahead['type']);

The main selling point for match is that it's more concise, I'm not
convinced that the return if variant is much less concise. If you want to
match more than one thing, use the OR (double pipe) operator in the if
condition.

Having said that=E2=80=A6 match is undeniably prettier. If we are doing thi=
s
however, I'd prefer to implement Go's switch block, named match because we
already have a switch. It's strict, but flexible.

- Davey

--0000000000003beaf005a64bba5e--