Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:11653 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 62598 invoked by uid 1010); 30 Jul 2004 07:34:35 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 60301 invoked from network); 30 Jul 2004 07:34:17 -0000 Received: from unknown (HELO iko.gotobg.net) (80.168.8.116) by pb1.pair.com with SMTP; 30 Jul 2004 07:34:17 -0000 Received: from pd9519681.dip.t-dialin.net ([217.81.150.129] helo=[192.168.0.32]) by iko.gotobg.net with asmtp (Exim 4.34) id 1BqRuD-0006bq-2W; Fri, 30 Jul 2004 10:34:17 +0300 Message-ID: <410A140A.3080008@hristov.com> Date: Fri, 30 Jul 2004 09:25:30 +0000 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8a2) Gecko/20040627 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jan Dittmer CC: internals@lists.php.net References: <20040729021337.73894.qmail@pb1.pair.com> <1091136355.490.4.camel@localhost> <1091139076.29517.12.camel@blobule.suds> <410991E1.6070000@hristov.com> <1091140927.29516.18.camel@blobule.suds> <41099925.4020700@hristov.com> <4109E7A2.2000701@ppp0.net> In-Reply-To: <4109E7A2.2000701@ppp0.net> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - iko.gotobg.net X-AntiAbuse: Original Domain - lists.php.net X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - hristov.com X-Source: X-Source-Args: X-Source-Dir: Subject: Re: [PHP-DEV] GOTO operator From: php@hristov.com (Andrey Hristov) Jan Dittmer wrote: > Andrey Hristov wrote: > >> Robert Cummings wrote: >> >>> >>> >>> Unmaintainable because of the ability to write cryptic code. There's >>> nothing cryptic about: >>> >>> ...code >>> >>> goto cleanup: >>> >>> ...code >>> >>> cleanup: >> >> >> do { >> .....code... >> if (something) break; >> ...code.... >> } while (0); >> ...cleanup code... >> > > This works for one level, but imagine: > > ... code ... (which exits with goto_out) > > if (!alloc x) > goto out; > > ... code ... (which exits with goto_outfreex) > > if (!alloc y) > goto out_freex; > > ... code ... (which exits with goto_outfreey) > > if (!alloc z) > goto out_freey; > > ... code ... > > free z; > out_freey: > free y; > out_freex: > free x; > out: > print bye; > > For this you'll need 3 nested do{}while(); loops and your indention is > so far to the right, that you can barely write more than two more words > on a line. > This really looks a lot cleaner with goto. I just woke up but I think this can be solved with one do..while and using bitfield for example. so when you break, just check the bitfield what to clean up. $clean = 0; do { $res = some_op(); if (!$res && $clean|=CLEAN_TYPE1) break; $res = some_op2(); if (!$res && $clean|=CLEAN_TYPE1) break; $res = some_op3(); if (!$res && $clean|=CLEAN_TYPE2) break; } while (0); if ($res & CLEAN_TYPE1) { //do clean type 1 } if ($clean & CLEAN_TYPE2) { // do clean type 2 } But I see that in your case simple variable and then having switch() after the do..while will be enough, just fall-through will be used. regards, andrey p.s. thanks for the nice example :) good exercise for the brain early in the morning :)