On Wed, Oct 16, 2019 at 4:37 AM Kosit Supanyo <webdevxp....@gmail.com>
wrote:

> I mean separation between cases not case conditions. Examples in your RFC
> uses semicolon as case separator instead of comma.
>
> <?php
> $say = switch (date("w")) {
>     case 0 => "weekend!";
>     case 1, 2, 3, 4, 5 => "weekday :(";
>     case 6 => "weekend!";
> };
> echo "Today is {$say}";
>
> I prefer comma because semicolon should only be used to separate statements
> but switch expression is list of condition/expression pairs not statements.
> So it should be:
>
>  <?php
> $say = switch (date("w")) {
>     case 0 => "weekend!",
>     case 1, 2, 3, 4, 5 => "weekday :(",
>     case 6 => "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ł Brzuchalski <
> michal.brzuchal...@gmail.com> wrote:
>
> > Hi Kosit,
> >
> > śr., 16 paź 2019 o 09:41 Kosit Supanyo <webdevxp....@gmail.com>
> > napisał(a):
> >
> >> Hi Michal
> >>
> >> I'had the idea similar to your RFC but instead of using `switch` keyword
> >> I think introducing `when` keyword is better. (as I know a language that
> >> uses this keyword is Kotlin)
> >>
> >> $result = when ($v) {
> >>     'foo' => 1,
> >>     'bar' => 2,
> >>     'x', 'y', 'z' => 3,
> >>     default => null,
> >> };
> >>
> >> Above you can see that `when` syntax is more semantic than `switch`. And
> >> 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 list
> >> expressions (array/function call).
> >>
> >> $result = switch ($v) {
> >>     case 'foo' => 1,
> >>     case 'bar' => 2,
> >>     case 'x', 'y', 'x' => 3,
> >>     default => null,
> >> };
> >>
> >
> > That's exactly my proposal with commas, see here:
> >
> https://wiki.php.net/rfc/switch-expression-and-statement-improvement#switch_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ł Brzuchalski
> >
>


-- 
Chase Peeler
chasepee...@gmail.com

Reply via email to