Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:11617 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12560 invoked by uid 1010); 29 Jul 2004 14:40:45 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 10183 invoked from network); 29 Jul 2004 14:40:23 -0000 Received: from unknown (HELO blobule.suds) (66.11.170.154) by pb1.pair.com with SMTP; 29 Jul 2004 14:40:23 -0000 Received: by blobule.suds (Postfix, from userid 501) id 9BED62F727; Thu, 29 Jul 2004 10:40:20 -0400 (EDT) To: lpedretti@suserver.com Cc: PHP Internals List In-Reply-To: <200407291117.09573.lpedretti@suserver.com> References: <20040729021337.73894.qmail@pb1.pair.com> <200407291117.09573.lpedretti@suserver.com> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8-3mdk Date: 29 Jul 2004 10:40:20 -0400 Message-ID: <1091112020.18112.15.camel@blobule.suds> Mime-Version: 1.0 Subject: Re: [PHP-DEV] GOTO operator From: robert@interjinn.com (Robert Cummings) On Thu, 2004-07-29 at 10:17, Leonardo Pedretti wrote: > Goto is somewhat equivalent to 'case' combined with using 'continue' in loops. > More precisely, this 2 language constructions are the 'goto' implementation > with a different name so that Dijkstra does not get back from the grave to > punish us =D > It is true that goto is a little 'off-paradigm' in OOP and truly structured > languages, however, the point is this: sometimes continue and case produce > code that is not so clear and small at the same time as a little well used > goto. BUT goto allows non experienced or not well educated programmers to > begin writing horrible and totally unstructured code, and go further > developing bad programming habits... IMHO, would php be a more restrictive > language (strongly typed, or something alike) I would be totally and > unconditionally on for a goto addon. However, i see the bad habits and bad > code promotion as something that should be very carefully noted before > deciding whether to apply it or not. > I hope i have added some good points to help make the consideration deeper and > better =) While it is true you can approximate the functionality of goto using switch, or if/elseif/else constructs, these are inferior in efficiency. Evaluation via switch or if/elseif/else system is O(n) just to get to the desired block of code. Using goto, getting to the chosen code block is O(1) (see note below). This is probably the most important reason why many parsing implementations use goto. Note ---- Goto jumping is O(1) if getting to the jump destination doesn't require a hash lookup due to "wuring" of the destination at compile time. If a hash lookup is required then it is probably something like O(lg n) which is still superior in efficiency to O(n). Additionally, while it is true that an O(lg n) lookup might be necessary at compile time to find the pointer to the labeled code block, this is a one time event and has little bearing on the efficiency overall when during runtime the goto might be hit thousands or millions of times. Cheers, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------'