On Mon, Feb 06, 2012 at 11:12:53AM -0500, Jim Giner wrote:
> NO "GO"!
> As one who started back in the 70's with old style coding that utilized GoTo 
> in Cobol, Fortran, etc. and had to deal with "spaghetti code" written by 
> even earlier developers who never considered that someone else would have to 
> maintain their code, I feel strongly that GoTo is not to be used.

I remember being faced with spaghetti code 35 odd years ago - yes, horrible.
But what do we mean by ''spaghetti code'' ? I remember code where every 3rd
statement was some form of GOTO - yuck!

One very desirable feature of code is that it be clear, ie: lucid, able to be
understood by others. Too many GOTO statements and it is hard.

However: a few GOTOs can make things clearer.  Think of a function that can fail
in several different places (eg data validation, ...).  But it is reading a file
which needs to be closed before the function returns.  I have seen code where
some $IsError variable is tested in many places to see if things should be done.
That is just as bad as lots of GOTO -- often when having to write something like
that I will have a GOTO (in several places) to the bottom of the function that
closes the file and returns failure.

That is much clearer than extra variables.

If I survey my code I find that I use one GOTO in about 4,000 lines of code -
that I do not find excessive.

There are, however, people who consider any GOTO as communion with the devil.
IMHO: not so - if used sparingly.

Alain Williams
Linux/GNU Consultant - Mail systems, Web sites, Networking, Programmer, IT 
+44 (0) 787 668 0256  http://www.phcomp.co.uk/
Parliament Hill Computers Ltd. Registration Information: 
#include <std_disclaimer.h>

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to