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.

> 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 would not be pleased to have it changed just to deal with your perceived 
> problem with it

I don’t suggest altering the behaviour of the switch statement but rather to 
introduce a new match statement.

Ilija


On 10 Sep 2017, 11:23 +0200, Tony Marston <tonymars...@hotmail.com>, wrote:
> wrote in message news:eb28362c-4f8f-45df-bbf0-582e8ad2b8af@Spark...
> >
> > Hi everybody!
> >
> > Has this idea been discussed before?
> >
> > I find myself writing switch statements in PHP quite rarely. This has a few
> > reasons:
> >
> > 1. It doesn’t have a "strict_types” version
> > 2. It is quite verbose (lots of breaks)
> > 3. It is a statement rather than an expression
> >
> > Often, if / elseif statements turn out to be shorter, safer and easier to
> > read than the switch statement.
> > What I’d really love is something like a match expression:
> >
>
> If there are circumstances where a series of if / elseif statements turn out
> to be shorter, safer and easier to read than a switch statement, then the
> intelligent thing to do would be to use if / elseif statements instead of
> trying to make the switch statement more complicated. If your problem with
> the switch statement is that you sometimes forget to insert a break
> statement then that is your fault. Try to use the language features as they
> were intended to be used and not how you would personally like to use them.
> Millions of other programmers have no problem with the switch statement, and
> they would not be pleased to have it changed just to deal with your
> perceived problem with it.
>
> --
> Tony Marston
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>

Reply via email to