On Tue, 2003-12-09 at 17:45, Justin Patrin wrote:
>
> While goto may be useful and even elegant for experienced programmers 
> (although I see no reason to use it myself with well structured 
> programs...there's always break), its inclusion in a language causes 
> some programmers (newbies and those who don't yet understand clarity, 
> etc.) to make habits which are harmful. It allows them shortcuts which 
> get things done, but often lead to bugs and hard to read code.

This is a good point that I do agree with. But experience comes with
knowledge about the tools, and goto is just another tool.

> <opinion>
> Personally, I don't think goto should ever be used. Well structured 
> programs can always be written to not need a goto and always just as 
> elegantly. It may take restructuring of code, but it can always be done, 
> and in the end the result is clearer.

The result is not always cleaner. Consider code with fairly complex
considtional branching (parsers are often in this category). Contrast 20
break statements and conditional re-entry variable to properly flow
through the code to the end of the  function where cleanup is performed
versus the same conditional branching complexity, with a single "goto
cleanup;". True one could put the cleanup in a function of it's own, but
then the usage of the function is just as unwieldy since it must be
populated with the data structures to cleanup. Alternatively an object
could be used, but now the code is spread out when it would have been
more clear in a single function with a label.

> 
> You say that a funciton is a "black box" and while this is true for the 
> user of a function, the maintainer of the code still has to deal with 
> the contents of the function. If you wrote and understand it, then fine. 
> The problem comes when others have to understand your code. Yes, a 
> single goto isn't all that bad, especially when it is used right, but is 
> it easier to screw up a code with a goto than a more structured 
> statement, such as break.
> </opinion>

I agree that when one writes code, they should always give consideration
to the person who must follow in their footsteps, but I still assert
that sometimes the code is easier to follow for the person who reads it
later when a goto is used than when multiple state variables are used to
manage flow control.

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 General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to