Re: Re: Long Live GOTO
| From: | Larry Martell | Date: | Mon, 06 Feb 2012 16:28:10 +0000 |
| Subject: | Re: Re: Long Live GOTO | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-316476@lists.php.net to get a copy of this message | ||
On Mon, Feb 6, 2012 at 9:23 AM, Alain Williams <addw@phcomp.co.uk> wrote:
> 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.
Just for another data point, the FAA does not allow gotos in any code
that goes into an airplane.