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. | `------------------------------------------------------------' -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php