Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!cmcl2!seismo!rlgvax!hadron!jsdy From: jsdy@hadron.UUCP (Joseph S. D. Yao) Newsgroups: net.lang.c Subject: Re: Jumping into blocks is a no-no (was: Re: An amusing piece of code) Message-ID: <376@hadron.UUCP> Date: Thu, 17-Apr-86 01:04:29 EST Article-I.D.: hadron.376 Posted: Thu Apr 17 01:04:29 1986 Date-Received: Sat, 26-Apr-86 04:01:58 EST References: <1370@ism780c.UUCP> <360@hadron.UUCP> <275@copper.UUCP> Reply-To: jsdy@hadron.UUCP (Joseph S. D. Yao) Organization: Hadron, Inc., Fairfax, VA Lines: 36 Summary: yecch! In article <275@copper.UUCP> stevesu@copper.UUCP (Steve Summit) writes: > if(stbuf.st_uid != getuid()) > { >nope: printf("I don't think you want to delete this file.\n"); > return; > } > if(strcmp(name, "vmunix") == 0) > goto nope; > unlink(name); > return; if (stbuf.st_uid != getuid() || strcmp(name, "vmunix") == 0) { printf("I don't think you want to delete this file.\n"); return; } unlink(name); return; If the conditions get any more complex, have your function return a value, and let the calling function perform the error condition (or not) depending on the value. It is n o t generally agreed that, just because goto's are used au hazard in UNIX code, that this is a good thing, even for error returns. I will defend the use of goto's in certain cases (and again cite Knuth), but this is not one of them, nor is any other attempt to jump into blocks. The pathological case (which occurs quickly) is called "spaghetti code." It is the bane of software engineers' lives. Oh, by the way, there are a lot of people who believe that examining UNIX source code shows you a lot of good code and a heckuvalotta very bad code. Case in point. -- Joe Yao hadron!jsdy@seismo.{CSS.GOV,ARPA,UUCP}