4 ms·
PHP was slated to gain a goto keyword How on earth did they decide this was a good idea? The points about getting rid of register_globals and safe_mode are gre
by aarongough 17y ago
PHP was slated to gain a goto keyword
How on earth did they decide this was a good idea? The points about getting rid of register_globals and safe_mode are great, but why add a feature to a programming language that is highly likely just to result in lots of awful code?
- shaunxcode 17y agobecause the whole 3 of us that compile lisp type languages into php need it for TCO.
- Scriptor 17y agoIt's not strictly necessary, tail recursion is enabled in Pharen (http://github.com/scriptor/pharen http://github.com/scriptor/pharen) by compiling it into a while loop. By the way, the docs on that page are way out of date so if anyone is interested feel free to contact me. EDIT: I'm an idiot, for tail calls of course it's a bit more complicated than just using a loop.
- pak 17y agoThere are ways to use goto effectively... in fact, the other day I was working with an awkwardly nested try/catch that would have read much clearer as a goto (and more efficiently; an empty Exception was being used to trigger the catch). I've seen this problem "solved" with a do while false and a break, but isn't that even hackier and less expressive? At this point I think goto-phobia is well understood enough that adding it for occasional use wouldn't ruin the language.
- aphyr 17y agoRuby distinguishes between begin/rescue (analogous to Java's try/catch) and throw/catch. I never understood it until discovering that throw/catch is perfect for dealing with nested cases where rescue or break fail. Also, it works through function calls and isn't interpreted as an error, which makes it great for cases like Ramaze's redirect or render calls; unlike in Rails, they interrupt execution immediately.
- tcdent 17y agoThis was discussed heavily when 5.3 was released, which back-ported it and the namespaces this article mentions. http://php.net/releases/5_3_0.php http://php.net/releases/5_3_0.php
- Batsu 17y agoThe page on GOTO actually includes a nice XKCD comic that illustrates both sides of the argument rather well. http://us3.php.net/goto http://us3.php.net/goto [Direct to comic] http://imgs.xkcd.com/comics/goto.png http://imgs.xkcd.com/comics/goto.png
- dhotson 17y agoIt's not all bad.. goto is actually a pretty good way to implement a state machine efficiently.