Hello,

On Thu, Jul 29, 2004 at 11:43:13PM -0700, Andi Gutmans wrote:
> [...]
> 
> Let's for a second skip discussion of the patch itself, because although it 
> was an interesting exercise the patch is not production ready.
> However, I think before talking about implementation, we need to decide if 
> goto is really good for PHP.
> We talked about it quite a bit at OSCON, and I must say that I personally 
> think that adding goto to PHP will do more harm than good.
> It is true that for some advanced programmers, goto can come in handy, but 
> the fact of the matter is that the PHP community has always taken a lot of 
> pride in providing a language which keeps away from these kind of shortcuts.

While the topic is fresh, I'm wondering if someone could share these oh so
mean shortcuts that have been kept out of PHP?

> I think there are only two cases where goto is really interesting:
> a) Error handling.
> b) Auto-generating code or compiler compilers (Sterling mentioned these 
> two).

c) File parsers
c) State machines

Although, I guess it comes down to how you define 'interesting'.

> I think that the cases where you need it for error handling in PHP code 
> aren't that great. Especially as the do..while(0) mechanism is much more 
> useful in PHP than in other languages due to the ability to do "break n;".
>
> This ability in my opinion, is a good argument for why it's not as relevant 
> in PHP as in other languages. And unlike someone mentioned in this thread, 
> it is actually pretty fast and also takes care of all of the ugly stuff 
> such as memory leaks from opcodes (not that it couldn't be implemented for 
> goto but I'm just giving some more info and why it's a good thing).
> 
> I think that although slightly harder, code generators can probably also 
> use similar constructs and survive without goto. I wouldn't want to add 
> such a construct just for code generation. Sterling suggested calling the 
> language construct something like "goto_only_use_for_autogenerated_code" 
> (you get the point). His reasoning was that he doesn't really think it's 
> needed by the average developer but it would be useful for automated tools. 
> Not something I can completely disagree with but I think the downside 
> outweighs the benefits.

But why make people developing such software use (a lot) more code than
necessary?  Why not let them decide which construct is more useful (to them)?

By adding support for the goto statement, code becomes simpler and more
intuitive, easier to maintain, and a lot less kludgey (I think the
do..while() approach is kludge, so maybe only the prior two count
for everyone else ;)

> I think that one can always find examples of how goto is useful, but it's 
> hard to think ahead of time of how badly it will be abused. From my 
> experience, although not quite as clear, it'll definitely be used in 
> spaghetti code and will overall encourage bad coding practices, especially 
> for less advanced programmers than people on this list.
> Yes, any programmer can shoot himself in the foot with other PHP features, 
> but we do have a responsibility to minimize that. One example is our 
> introduction of E_STRICT. We don't warn about enough things but we do try. 
> Why give our developers yet another way of shooting themselves in the foot? 
> Or should I say, blow off their leg? :)

Again with the foot shooting.  Can we please remove include()/require(),
$_GET/$_POST/$_COOKIE, procedural programming and OOP support...  just
in case the user decides to develop Shotgun.php, include()'s it and
executes MyPowerfulDeathGun::shoot_my_foot($_REQUEST['num_bullets']) ?

--
Elfyn McBratney
(a long time PHP user/hacker, who would love to see goto support)

PGP Key ID: 0x456548B4
PGP Key Fingerprint:
  29D5 91BB 8748 7CC9 650F 31FE 6888 0C2A 4565 48B4

Attachment: pgpnE2TwX626r.pgp
Description: PGP signature

Reply via email to