"while/else" (ugh) (was Re: [oclug] Ruby)

Francis J. A. Pinteric linuxdoctor at linux.ca
Fri Jun 27 23:02:19 EDT 2003


On Fri, 27 Jun 2003 22:11:16 -0400 (EDT)
"David F. Skoll" <dfs at roaringpenguin.com> wrote:

> On Fri, 27 Jun 2003, Francis J. A. Pinteric wrote:
> 
> > `goto' constructs are anathema!
> 
> Not necessarily.  You'll find them all over the Linux kernel, for
> example.

So what?


> 
> Goto, used judiciously, can be quite clear, and can even simplify the
> code.  Which is clearer:
> 
> (a)
> 
> 	while(condition1) {
> 		while(condition2) {
> 			while(condition3) {
> 				if (exception) goto bailout
> 			}
> 		}
> 	}
> bailout: // foo
> 
> or (b):
> 
> 	while(condition1) {
> 		while(condition2) {
> 			while(condition3) {
> 				if (exception) {
> 					flag=1;
> 					break;
> 				}
> 			}
> 			if (flag) break;
> 		}
> 		if (flag) break;
> 	}
> // foo
> 
 

Again, so what?  When we deal with hypothetical code, we can come up
with objections to all sorts of constructs. Also, we can provide
supporting constructs to suit our own perspective.  If one wraps one's
minds around how a particular language works, one tends to adapt to it's
own peculiarires.

Remember the whole "I hate gotos" movement was begun because of the
feeling that structured programming could conquer all.  Coming out of
the age of FORTRAN and IBM 360 ASSEMBLER, good code was seen to be code
without gotos.  Some people took it to extremes, of course, and there is
a place for gotos.  However, to use gotos as an excuse for bad code is
never acceptable.

As humanity discovered how to make their computer inventions perform to
their satisfaction, they ended up as explorers in self constructed
frontiers.  Part of that exploration mandated that `gotos' was very bad
indeed.

If you `goto' out of necessity, fine.  If you `goto' because you're
lazy, then shame on you.


> > Didn't you read all those papers in the late '70's about goto-less C
> > code? :-)
> 
> I didn't read them *all* :-)  But a blanket ban on "goto" is
> unwarranted.
> 


Isn't hind-sight wonderful?  However, what the goto-less philosphy was
about wasn't really about `gotos' was it?

>>>--fja->

-- 
Fashion is for people who have no style.

There are three crimes which deserves the death penalty:
conformity, political correctness, and smoking.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://tux.oclug.on.ca/pipermail/oclug/attachments/20030627/44465384/attachment.bin


More information about the OCLUG mailing list