Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:11631 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76628 invoked by uid 1010); 29 Jul 2004 22:48:04 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 76501 invoked from network); 29 Jul 2004 22:48:03 -0000 Received: from unknown (HELO utopia.rusko.us) (207.44.144.89) by pb1.pair.com with SMTP; 29 Jul 2004 22:48:03 -0000 Received: from rusko (ool-44c0a1af.dyn.optonline.net [68.192.161.175]) by utopia.rusko.us (Sendmail) with SMTP id B5F61BBBAB for ; Thu, 29 Jul 2004 19:07:58 -0400 (EDT) Message-ID: <004801c475bd$812f3580$0200a8c0@rusko> To: References: <20040729021337.73894.qmail@pb1.pair.com> <200407291117.09573.lpedretti@suserver.com> <200407291037.12396.ilia@prohost.org> <41098F91.3000606@hristov.com> Date: Thu, 29 Jul 2004 18:43:44 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 Subject: Re: [PHP-DEV] GOTO operator From: paul@rusko.us ("Paul G") ----- Original Message ----- From: "Andrey Hristov" To: Cc: Sent: Thursday, July 29, 2004 8:00 PM Subject: Re: [PHP-DEV] GOTO operator --- snip --- > Is the average Joe going to write parsers in the everydays work? Probably not. how about: function pseudocode() { $a=allocate_resource_z(); $b=allocate_resource_y(); $res=do_stuff(); if(!$res) goto err_out; $c=allocate_resource_x(); $res=do_more_stuff(); if(!$res) goto err_out; $d=allocate_resource_foo(); $res=do_even_more_stuff(); if(!$res) goto err_out; return true; err_out: free_resouce($a); free_resouce($b); if(isset($c)) free_resouce($c); if(isset($d)) free_resouce($c); return false; } here the do_stuff()s would be trivial inline code that makes no sense to break out, each being a few slocs. everything looks neat and it is perfectly clear what is going on. with no goto: function pseudocode() { $a=allocate_resource_z(); $b=allocate_resource_y(); $res=do_stuff(); if(!$res) { free_resource($a); free_resource($b); return false; } $c=allocate_resource_x(); $res=do_more_stuff(); if(!$res) { free_resouce($a); free_resource($b); free_resource($c); return false; } $d=allocate_resource_foo(); $res=do_even_more_stuff(); if(!$res) { free_resouce($a); free_resource($b); free_resource($c); free_resource($d); return false; } return true; } .. now imagine this isn't pseudocode, but actual code. you're doing a bunch of stuff and the repetition becomes extremely unmanagable, especially if you are doing miantenance later. ie, say you allocate another resource at the beginning - add a free_resource() in one place only with the goto example, in N places without. before you discount the resource allocation stuff (in C this would be primarily malloc()s), there is quite enough stuff that you can 'allocate' in real code that isn't going to get gc'ed. and yes, i've been missing goto dearly when doing real development. right now, i'm emulating it by implementing allocation functions such that they keep a list (or hashtable rather) of resources belonging to each function and i can release them all in one line of code, but i'm still replicating that line of code everywhere and, quite frankly, it's a kludge. i agree with ilia - dont' castrate the language in a misguided effort to protect the clueless. abuse of goto is best prevented by education on its proper uses (few very specific cases). paul