Path: utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!cs.utexas.edu!usc!ucsd!ucselx.sdsu.edu!petunia!polyslo!jdudeck From: jdudeck@polyslo.CalPoly.EDU (John R. Dudeck) Newsgroups: comp.lang.c Subject: Re: if (e1) return e2; [else] s1; Message-ID: <260d673a.2922@polyslo.CalPoly.EDU> Date: 26 Mar 90 00:50:02 GMT References: <887@dino.cs.iastate.edu> Reply-To: jdudeck@polyslo.CalPoly.EDU (John R. Dudeck) Organization: Cal Poly State University -- San Luis Obispo Lines: 32 In article <887@dino.cs.iastate.edu> hascall@cs.iastate.edu (John Hascall) writes: > > Ok, style mavens, which is "better": > > if (e1) return e2; if (e1) return e2; > else s1; s1; I can't think of any reason why one is better than the other, but I think that the second one indicates that you have thought through the logic of the routine enough to realize that the 'else' is superfluous. Whenever I notice that I have done the first, I always change it to remove the else. > >--------------------------------------------------------------- > I'm not sure which of the above is better, but I am sort of > "stuck on" the following convention: > > if (e1) s1; \ > --or-- \ > if (e1) { | Does this seem reasonable? > s1; | (ignoring whether or not the `{' > } | belongs on the next line or not) > --but never-- | > if (e1) / > s1; / > I discovered a good reason to use the third form. When you are debugging with CodeView, if the action is on a separate line from the condition you can breakpoint on the action, and it will only break if that branch is taken. Similarly, you can single step and have it stop on the action part. Otherwise I always use the first two (including your placement of '{' ). -- John Dudeck "You want to read the code closely..." jdudeck@Polyslo.CalPoly.Edu -- C. Staley, in OS course, teaching ESL: 62013975 Tel: 805-545-9549 Tanenbaum's MINIX operating system.