Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:107557 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 70797 invoked from network); 16 Oct 2019 15:57:42 -0000 Received: from unknown (HELO php-smtp3.php.net) (208.43.231.12) by pb1.pair.com with SMTP; 16 Oct 2019 15:57:42 -0000 Received: from php-smtp3.php.net (localhost [127.0.0.1]) by php-smtp3.php.net (Postfix) with ESMTP id 3A65D2D1FA4 for ; Wed, 16 Oct 2019 06:42:07 -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=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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: Error (Cannot connect to unix socket '/var/run/clamav/clamd.ctl': connect: Connection refused) Received: from mail-vk1-xa2e.google.com (mail-vk1-xa2e.google.com [IPv6:2607:f8b0:4864:20::a2e]) (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 ; Wed, 16 Oct 2019 06:42:06 -0700 (PDT) Received: by mail-vk1-xa2e.google.com with SMTP id s72so5184558vkh.5 for ; Wed, 16 Oct 2019 06:42:06 -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=JwjSC+0N9Ee0BEeo+1NfKKETJ7wm2lumb/sMi7b+KxY=; b=bHn8rWndCHWCc4IZuetKvfginFIgWTRJu5n7sZN/EZgQF0+qPRaHc32m6o5qAHlrfO ouXEbR9GcRtS/Ic62GFmCSTcWQIdvcjYHf5O04MgfUHCEhvBwPfw4CM9Td/m5bCMjk86 tCzbBbEyQMjO0ae7O6lHa8ZNjs3abwPdczEY2izBp6pmMRj4ttBLviPKtCiHDc9fAP1X X33QnP7MpV3qISni9Tg/MJzKCqmoGkZ+G6ws1GpYB4KnpYrt/8BfYoMoDJSTuIDEG7Ym LDMYrNAv8oS60GsfzkeNKHT6L1HmP36s9vI53svsOO9lXHMinKz95HKiSvt1EMFL8fHN pg7Q== 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=JwjSC+0N9Ee0BEeo+1NfKKETJ7wm2lumb/sMi7b+KxY=; b=Z4Z+9t5YGGj+QXlPIbH83z0pwi36ZJHRgv6c1+Ucg42qcXi4IFVbPGMVBUI5+Laz2i 7WDzPErdw+E3lxq3TYeWTmC7ZBb9Kn922F2Bo/K+rhPd5sFem4ZtSetdAaZFkxa7Me88 YP07Rtr94LQm4uK/MU/gvmmnuPUeYojjh6eIw0Dbm7Cfj8iEdx7MTNFfKzasZ8zHM5/l RkBHCnUUyEGK7Wb2JnE/XBmar3II4XxO2f4s2OdwMUSVvqb/xlHC5rQQAuU6NsJr9sfx QPRjnq4mVbgj3set5vArJ0is9/nP0ezLgYzIf/rWRVMPmfQ815ms7EBU0ncpWYSdrNJM hgrg== X-Gm-Message-State: APjAAAWb3YmPr8va5AuvutQxD+TX5HqT97MxFysMU1o06YUVM6tDgIx0 jYvOzBjUoR8rpj5T7BpIW2ufOAzqaras1bIHHSs= X-Google-Smtp-Source: APXvYqyipiut9dc1B4r5J59GrptkPot+uGqs2Oe4EmURroKCKGf+RA/MBGCX1uH3GpbeZlTIMqCEPvmWcJcmk8g6TAM= X-Received: by 2002:a1f:5846:: with SMTP id m67mr21923490vkb.13.1571233325851; Wed, 16 Oct 2019 06:42:05 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Wed, 16 Oct 2019 09:41:54 -0400 Message-ID: To: Kosit Supanyo Cc: =?UTF-8?Q?Micha=C5=82_Brzuchalski?= , PHP Internals List Content-Type: multipart/alternative; boundary="0000000000003f27d5059507440a" X-Envelope-From: Subject: Re: [PHP-DEV] Inline switch as alternative to nested inline conditional From: chasepeeler@gmail.com (Chase Peeler) --0000000000003f27d5059507440a Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Wed, Oct 16, 2019 at 4:37 AM Kosit Supanyo wrote: > I mean separation between cases not case conditions. Examples in your RFC > uses semicolon as case separator instead of comma. > > $say =3D switch (date("w")) { > case 0 =3D> "weekend!"; > case 1, 2, 3, 4, 5 =3D> "weekday :("; > case 6 =3D> "weekend!"; > }; > echo "Today is {$say}"; > > I prefer comma because semicolon should only be used to separate statemen= ts > but switch expression is list of condition/expression pairs not statement= s. > So it should be: > > $say =3D switch (date("w")) { > case 0 =3D> "weekend!", > case 1, 2, 3, 4, 5 =3D> "weekday :(", > case 6 =3D> "weekend!", > }; > echo "Today is {$say}"; > > While using colons and semicolons would better sync up with current switch syntax, I definitely like using arrows and commas better. My only issue* is the fact that this introduces multiple ways to do the same thing, which I thought was confusing and bad for new developers *Not really an issue, just being a bit snarky. I actually love proposals like this. It adds something useful to the language, people that don't like it don't have to use it, and the positives outweigh the negatives in terms of BC breaks (which are none, in this case, making it really easy to outweigh them). You may think t's fine because Java uses semicolon but IMO Java had made a > mistake. (C# is semantically correct) > > Cheers > > On Wed, Oct 16, 2019 at 2:54 PM Micha=C5=82 Brzuchalski < > michal.brzuchalski@gmail.com> wrote: > > > Hi Kosit, > > > > =C5=9Br., 16 pa=C5=BA 2019 o 09:41 Kosit Supanyo > > napisa=C5=82(a): > > > >> Hi Michal > >> > >> I'had the idea similar to your RFC but instead of using `switch` keywo= rd > >> I think introducing `when` keyword is better. (as I know a language th= at > >> uses this keyword is Kotlin) > >> > >> $result =3D when ($v) { > >> 'foo' =3D> 1, > >> 'bar' =3D> 2, > >> 'x', 'y', 'z' =3D> 3, > >> default =3D> null, > >> }; > >> > >> Above you can see that `when` syntax is more semantic than `switch`. A= nd > >> it is easier to implement in parser because it has no > statement/expression > >> ambiguity. > >> > >> But this might not be preferred by BC camps because introducing a new > >> keyword might break BC. > >> And if `switch` is chosen I still think the syntax should be comma > >> separated instead of semicolon separated for consistency with other li= st > >> expressions (array/function call). > >> > >> $result =3D switch ($v) { > >> case 'foo' =3D> 1, > >> case 'bar' =3D> 2, > >> case 'x', 'y', 'x' =3D> 3, > >> default =3D> null, > >> }; > >> > > > > That's exactly my proposal with commas, see here: > > > https://wiki.php.net/rfc/switch-expression-and-statement-improvement#swit= ch_expression_introduction > > Unfortunately, this RFC needs more work cause it mixes switch statement > > enhancement with comma-separated list syntax and of switch statement - = I > > need to split it into two RFC's > > > > This is nice hearing that this idea has an interest. > > As soon as the RFC will be split and finished I can start a discussion > > thread. > > > > Cheers, > > Micha=C5=82 Brzuchalski > > > --=20 Chase Peeler chasepeeler@gmail.com --0000000000003f27d5059507440a--