Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!rpi!uupsi!fozzie!stanley From: stanley@phoenix.com (John Stanley) Newsgroups: comp.lang.c Subject: Re: Coding Standards. was: a style question Message-ID: Date: 17 Nov 90 06:07:05 GMT Organization: One Man Brand Lines: 38 imp@marvin.Solbourne.COM (Warner Losh) writes: >This is a bogus restriction, at least in terms of a single exit point. >When you have small functions, the return statement can be used to >give meaningful flow control to the functions w/o the need for a >"goto". >>lots of code deleted<< >A quick check reveals that the above code segments are all the same. >However, I may have missed something. The final one is the clearest >one, IHO, of them all. Comments.... Ooh, an invitation for comments! The main advantage to having one exit point is that it is easier to be sure any necessary cleanup is performed prior to exit. It can be quite messy when cleanup code is distributed in multiple copies throughout the file. The example that I deleted involved opening files, then doing something, then exiting if that something caused an error. This type of situation makes it very easy to forget to close that file. If you call this function many times, and have many errors, you will eventually run out of files. It was just this bug I found in some production code, a year after it was released. I put the software into a neverending demo loop during a trade show and noticed that it started complaining about "no more units" after 20 minutes or so. The code was bullet proof enough that it didn't crash, just could no longer access any data. If the code had had but one exit from that routine, it would probably have never had that bug get by. <> "Aneth! That's a charming place!" "You've been to Aneth?" <> "Yes, but not yet." -- The Doctor and Seth, "The Horns of Nimon". >< <> "Sanity check!" "Sorry, we can't accept it, it's from out of state." - me