Re: Re: [RFC] Match expression

From: Date: Sun, 10 Sep 2017 10:32:48 +0000
Subject: Re: Re: [RFC] Match expression
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-100499@lists.php.net to get a copy of this message
> it makes it impossible to group several conditions with a single break In Swift you can group multiple conditions with a comma , and in Rust with a pipe |. Here’s how that could look in PHP: ```php match ($x) {     1, 2: ‘One or two’; } ``` The only thing you cannot do is this: ```php switch ($x) {     case 1:         echo “One\n”;     case 2:         echo “Two\n”;         break; } ``` Meaning you cannot “bleed through” the first case into the second, executing both in case of $x being 1. This is acceptable IMO because this looks like a bug even if it’s intended. >  then why can't you use if/elseif instead of making the language more complicated? Because that’s usually the perfect use case for a switch statement. On 10 Sep 2017, 12:22 +0200, Tony Marston <TonyMarston@hotmail.com>, wrote: > wrote in message > news:7cd2884a-6606-4c3f-8f95-776fd277878b@Spark... > > > > Hi Tony > > > > > … you sometimes forget to insert a break statement then that is your > > > fault. > > > > Any bug in your source code is ultimately your fault. But as mentioned > > before human error is inevitable. You can make it easier for your users to > > make less mistakes though. Other languages (e.g. Rust or Swift) have > > implicit breaks in their switch statements. This has been done for a > > reason, I wouldn’t call this a non-issue. > > The problem with implicit breaks is that it makes it impossible to group > several conditions with a single break. My previous language use implicit > breaks, and this problem really annoyed me. With PHP I have more control, > and the fact that I have to insert explicit breaks I do not see as an > inconvenience. > > > > Millions of other programmers have no problem with the switch statement > > > > It’s all they know. They don’t complain about null pointers even though it’s > > inventor calls it his billion-dollar mistake. The customer rarely knows > > what he truly needs. > > They know what they want to achieve, and they have to know which language > features are available to help them meet their objectives. The fact that > some language features have turned out to be a big mistake is purely the > fault of the people who introduced those features. Some programmers complain > about some languages features even though they are useful features which > work as advertised as are not deemed to be a mistake - take yourself for > example who is now complaining about issues with the switch statement. > > If what you want to achieve can be done better with a series of if/elseif > statements than the switch statement, then why can't you use if/elseif > instead of making the language more complicated? > > -- > Tony Marston > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.internals (#100499) next »