On Mon, Feb 6, 2012 at 9:50 AM, Adam Richardson <simpleshot@xxxxxxxxx> wrote: > On Mon, Feb 6, 2012 at 11:28 AM, Larry Martell > <larry@xxxxxxxxxxxxxxxxxxxxx>wrote: > >> On Mon, Feb 6, 2012 at 9:23 AM, Alain Williams <addw@xxxxxxxxxxxx> 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. >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > Can I have the source for this so I can read the rationale? I'm curious > which language implementation it's referencing (C, Ada, etc.) and what > restrictions the language places on the construct. Again, the PHP version > of the construct is beneficially quite restrictive. For instance, some > people don't like giving programmers access to pointers just because you > can get into so much trouble with them, but I wonder if they'd be concerned > about Go's pointers, which don't allow pointer arithmetic, limiting one are > of potential trouble: > > http://golang.org/doc/go_for_cpp_programmers.html#Conceptual_Differences > > Interesting. The source is my own personal experience working for an avionics company and working with the FAA to get our code certified under the DO-178B standard. I never saw anything that said 'no GOTOs' but that's what I was told. I was also told no C++ was allowed nor was any recursion. This was important to me, as we had purchased some code that was all that (C++, with recursion and GOTOs) and I was given the task of rewriting it in C and removing the gotos and the recursion. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php