|
|
Subscribe / Log in / New account

The winding road to PHP 8's match expression

The winding road to PHP 8's match expression

Posted Sep 2, 2020 18:50 UTC (Wed) by mathstuf (subscriber, #69389)
In reply to: The winding road to PHP 8's match expression by professor
Parent article: The winding road to PHP 8's match expression

Maybe better wording would be "when I intend it to happen, it is useful"? That's my experience with it in C. There have been numerous times that I've been disappointed to have to add a missed `break;` in a switch statement (C, but that's where PHP got its idea for switch; if C didn't have it, I really doubt PHP would have fallthrough).


to post comments

The winding road to PHP 8's match expression

Posted Sep 2, 2020 20:10 UTC (Wed) by professor (subscriber, #63325) [Link] (3 responses)

Yes, because I know when i want the behaviour! PHP is, in my opinon, a powerful extension for C.
If i want a break i would put it there and if not i would not.. Todays (-fifteen years) "i want everything on a silver plate and stuff i dont know about is someone else´s fault and thefor bad design" is just weird.. PHP have always been what it is according to the manual (which is one of the best) but if you dont want to read it and dont know what you are doing you just dont know.. even if this is "crap" it made it possible to create some awesome (first) results without knowing anything (which made it great but also is the black sheep nowadays).

yes, i love PHP :)

The winding road to PHP 8's match expression

Posted Sep 2, 2020 21:41 UTC (Wed) by mathstuf (subscriber, #69389) [Link] (1 responses)

> Yes, because I know when i want the behaviour!

This mentality works for solo projects (and even then, more towards the one-off end of things). In my experience, having such sharp tools laying around with opt-in safety mechanisms make code review and later maintenance much harder. An explicit `fallthrough;` statement would have been a better solution rather than `break;`. Why? I find fallthrough to be the rarer case. Sure, Duff's device is cool and all, but I've written one maybe once? Seen it only a few other times? Making it have a few more keyword instances would have been fine (especially since your indentation is already all kinds of whack most of the time, doing `fallthrough; case …` would probably have worked).

> "i want everything on a silver plate and stuff i dont know about is someone else´s fault and thefor bad design" is just weird

I know about it and I even use it sometimes. I still comment when I explicitly mean for fallthrough to happen because I'm not the only one working on the code in question (even if another person isn't, years-later me might have to figure out what the code in question is doing anyways).

The winding road to PHP 8's match expression

Posted Sep 2, 2020 22:29 UTC (Wed) by professor (subscriber, #63325) [Link]

You are perhaps right in a modern sense indeed.. Not everyone is like you though.

This part i dont understand at all..

"Sure, Duff's device is cool and all, but I've written one maybe once? Seen it only a few other times? Making it have a few more keyword instances would have been fine (especially since your indentation is already all kinds of whack most of the time, doing `fallthrough; case …` would probably have worked)."

The winding road to PHP 8's match expression

Posted Sep 2, 2020 22:56 UTC (Wed) by mjg59 (subscriber, #23239) [Link]

"i want everything on a silver plate and stuff i dont know about is someone else´s fault and thefor bad design"

What we want is code that doesn't have bugs. All the evidence suggests that the number of people who can write code that doesn't contain bugs is extremely small, which means designing languages such that it's harder to write bugs is a reasonable choice.


Copyright © 2025, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds