Newsgroups: comp.lang.c Path: utzoo!henry From: henry@utzoo.uucp (Henry Spencer) Subject: Re: Is an argument to break, continue a bad idea? Message-ID: <1990May4.165746.15724@utzoo.uucp> Organization: U of Toronto Zoology References: <1990Apr25.180007.13243@cunixf.cc.columbia.edu> <591@atcmpe.atcmp.nl> <738@mwtech.UUCP> <1990Apr30.165059.1839@utzoo.uucp> <742@mwtech.UUCP> Date: Fri, 4 May 90 16:57:46 GMT [Puzzled comp.lang.c readers, note that this has moved over from comp.std.c.] In article <742@mwtech.UUCP> martin@mwtech.UUCP (Martin Weitzel) writes: > ..... { > ..... { > ..... { > /* > Here we are in some complicated nested > conditions and loops. Suddenly something > very ugly happens... Diagnosis: excessively nested control structures. The remedy is to re-read K&R1 chapter 4 about the most important control structure of all: functions. In 15 years of active C programming, I don't think I have ever used a goto in original code. (Once or twice I have used one in maintaining code that was already full of them, when I didn't have time to redo it.) I attribute this mostly to a strong distaste for deep nesting. Breaking things up into functions makes life easier in a lot of ways, not least of them being the ability to use `return' to get yourself out of messes. Amazingly enough, when you do this systematically, you find that you seldom have any desire to use `goto'. It just isn't needed. >>... When you see "goto", you don't know where it goes without >>hunting for the label, and you don't know if anything else goes to that >>label without searching the whole function for more gotos... > >Really? >What is your argument? If you wanted to say that `break' is preferable >over `goto', you must have a *very* advanced syntax directed editor. >With a normal editor (like "vi"), I'll have less problems to hunt for >`goto's (with labels!) than for `break'... I don't care much for `break' either, although I concede its necessity in some cases because C lacks higher-level constructs to do certain jobs. Mind tend to come with comments like `/* NOTE BREAK OUT */' to make them more conspicuous. >If you recommend to avoid >`break' too, then what about the additional flags for breaking >out of loops. Don't they suffers from the same problems(%)? ... I recommend composing programs in an orderly way to avoid the need, mostly. >... IMHO flags often obscure >things that would be clarified by DISCIPLINED USE OF `goto's. Yes, it's better to simply avoid both. -- If OSI is the answer, what is | Henry Spencer at U of Toronto Zoology the question?? -Rolf Nordhagen| uunet!attcan!utzoo!henry henry@zoo.toronto.edu