Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107577 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53414 invoked from network); 18 Oct 2019 22:00:18 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 18 Oct 2019 22:00:18 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 558762D205F for ; Fri, 18 Oct 2019 12:45:16 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp3.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS3215 2.6.0.0/16 X-Spam-Virus: No Received: from mail-yw1-xc31.google.com (mail-yw1-xc31.google.com [IPv6:2607:f8b0:4864:20::c31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp3.php.net (Postfix) with ESMTPS for ; Fri, 18 Oct 2019 12:45:15 -0700 (PDT) Received: by mail-yw1-xc31.google.com with SMTP id i207so2575169ywc.9 for ; Fri, 18 Oct 2019 12:45:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=newclarity-net.20150623.gappssmtp.com; s=20150623; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=SwkY+vQ8kOZG8FuyMU8C1FKLQX/HwKdb44PuSkAHRMA=; b=FBE08UD3AQAnp0G0IR4M40SCF7oDTYclRVSXJ6z9/0Y2dDgR3FEqCUgtNI8cP0iaZG oTSbtNzgoqohjKjD72tYldx6dSED5j82a8F2MctQBCbeet3lQDYvjCHhydjF5JYYkvTk D02PvA7rOuasOtJHDeUxqLATdW6djLvq+sHrwTPpQ8dsGzdKEq8erc6MknYbS84WLy1p W8p91E0y0X70x+8XsF67jRQOybUEftUSzuKY7SD/txc0svC7Jch3uJw/0MTTniDDGiZ6 CFcLl02AmesFD8fvvboHHx/LQgCpQp9jRGzC6I1n5DUSqnizkv1Y1xmYE8uu1z7n70qG aCpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=SwkY+vQ8kOZG8FuyMU8C1FKLQX/HwKdb44PuSkAHRMA=; b=VNX2D9Rttb791N3kkUrvhLHCizWu+HpfquKmA2zQrc/OGBreFNPhiWDjphwufwLtuv cJTnXFpqBTxbBuAoX/0RjXX5DbPTGK2e47f9Trjz6OziAVvJBHqAxa3qQRs8AOZAeDDz IehkVFLrOj46x6H5jgzS3kgJhI0nuAllssy66OBBw3a9Es4B1pWe3KedW2dNai8KWu5L /1CviapiBimxa0kRh59DIFd8BwobeTAUyRdJKtu9BE3ox2qgLQ7/2FcXtW/qHPd5oF/Q 2KKtNX0nIONf+FpMR7hrMriQ/0paG8drGC2plVh3fwn03HotD3l/kD1M/wYSQ1/itWXV neuA== X-Gm-Message-State: APjAAAV1P4e5Klq7U7mREvvtHLyz/k67aKFrn+jdbiinAtF5sECxrO3T SVAktQMRcusMVP9FZBYPAoioJg== X-Google-Smtp-Source: APXvYqzVaXoXSN+BpWt7u6m/81l9SPBmVCE62wUOLorKlOmqOwlBqOd6Yxt2A78HCtbiGgpuHXX5uA== X-Received: by 2002:a81:9146:: with SMTP id i67mr7919374ywg.157.1571427915205; Fri, 18 Oct 2019 12:45:15 -0700 (PDT) Received: from ?IPv6:2601:c0:c67f:e34e:e967:8db7:ce56:c182? ([2601:c0:c67f:e34e:e967:8db7:ce56:c182]) by smtp.gmail.com with ESMTPSA id w123sm1731794yww.22.2019.10.18.12.45.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 18 Oct 2019 12:45:14 -0700 (PDT) Message-ID: Content-Type: multipart/alternative; boundary="Apple-Mail=_E62D73C7-0FE4-4707-8E98-1A18942EE0E3" Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Date: Fri, 18 Oct 2019 15:45:13 -0400 In-Reply-To: Cc: David Rodrigues , PHP Internals List To: =?utf-8?Q?Micha=C5=82_Brzuchalski?= References: X-Mailer: Apple Mail (2.3445.104.11) X-Envelope-From: Subject: Re: [PHP-DEV] Inline switch as alternative to nested inline conditional From: mike@newclarity.net (Mike Schinkel) --Apple-Mail=_E62D73C7-0FE4-4707-8E98-1A18942EE0E3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Oct 15, 2019, at 11:33 PM, Micha=C5=82 Brzuchalski = wrote: >=20 > I have an RFC in draft for that and planning to finish it soon = together > with some syntax optimisations - you can see it at > https://wiki.php.net/rfc/switch-expression-and-statement-improvement >=20 > Cheers, > Micha=C5=82 Brzuchalski In an earlier message I said I would return to comment on some concerns = I have with the RFC. In general, I would appreciate having a way to express a "switch" in an = expression much like how you can express an "if" with the ternary = operator. However, the specifics of your suggestion give me pause.=20 Also, some of my concerns are contradictory to each other which I will = admit in advance. 1. I am a strong believer in language design that facilitates = refactoring. But your syntax would make refactoring from an existing = switch harder than it would need to be if the syntax more closely = matched the existing switch. =20 In your proposal you replace colons (:) with fat arrows (=3D>) which has = no perceptible benefit, at least not for me: $say =3D switch (date("w")):string { case 0 =3D> "weekend!"; case 1, 2, 3, 4, 5 =3D> "weekday :("; case 6 =3D> "weekend!"; }; The same logic in today's PHP: switch (date("w")) { case 0:=20 $say =3D "weekend!"; break case 1, 2, 3, 4, 5:=20 $say =3D "weekday :("; break case 6: =20 $say =3D "weekend!"; }; It would be easier to manually refactor if mostly the same syntax was = used, e.g. with colons (") vs. fat arrows (=3D>): $say =3D switch (date("w")):string { case 0: "weekend!"; case 1, 2, 3, 4, 5: "weekday :("; case 6: "weekend!"; }; So if I had a vote I would vote likely against your RFC with the fat = arrows but for it if you changed it to use colons instead. 2. However, I find the above more verbose than would be ideal, and I = would like an optional equivalent of the ternary operator, e.g. both a = verbose option and a terse option. I said optional above because =E2=80=94= unlike the stated preferences of others here on this list =E2=80=94 I = celebrate having multiple ways to accomplish the same task because some = approaches fit a given use-case better than other approaches. What might a terse option look like? Maybe this, although I might have = missed conflicts to the existing language: $say =3D date("w"):string ??? =20 0: "weekend!";=20 1, 2, 3, 4, 5: "weekday; :(";=20 6: "weekend!"; $default; I will say, one huge benefit to an inline switch would be allowing for = switch logic without requiring a `break` (or an explicit `fallthrough`) = and without any backward compatibility concerns, at least for some = use-cases. -Mike --Apple-Mail=_E62D73C7-0FE4-4707-8E98-1A18942EE0E3--