Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site watmum.UUCP Path: utzoo!watmath!watnot!watmum!cdshaw From: cdshaw@watmum.UUCP (Chris Shaw) Newsgroups: net.lang.c Subject: Re: how has C bitten you? (Really, style) Message-ID: <259@watmum.UUCP> Date: Wed, 21-Aug-85 20:41:39 EDT Article-I.D.: watmum.259 Posted: Wed Aug 21 20:41:39 1985 Date-Received: Sat, 24-Aug-85 03:12:57 EDT References: <302@brl-tgr.ARPA> <4081@alice.UUCP> <243@ecrhub.UUCP> <123@ecsvax.UUCP> <389@phri.UUCP> <372@ttrdc.UUCP> Reply-To: cdshaw@watmum.UUCP (Chris Shaw) Distribution: net Organization: U of Waterloo, Ontario Lines: 44 In article <372@ttrdc.UUCP> levy@ttrdc.UUCP (Daniel R. Levy) writes: >In article <389@phri.UUCP>, roy@phri.UUCP (Roy Smith) writes: >> Here's one that just got me: >> if (sv > score); <----- note extraneous semi-colon >> score = sv; > >Sounds like a question of style hiding function. Why not stick to something >like > if (sv > score) score = sv; >? >| dan levy ...because if(sv>score||this==that+the_other||fopen("crap","r"))save=the+whales+fur+christ++; is the kind of statement where bugs really happen. Can you seriously spend less than two seconds reading that to comprehend what's going on ? If you answered yes, how about this (more important) question: Can you read a whole FILE of this kind of crap and then be able to find a variable at will ? I doubt it. I can think of more straightforward ways of producing code, some of which include programming while awake, so that the errors like the one in the original posting don't happen. Others include using a self-consistent style, which Mr Levy's is not. Compound if statements should look the same as simple if statements. Mr Levy's style of if statement has an equivalent in English called "the run-on-sentence". What's silly about the whole thing is that a program formatter can make this stuff QUITE readable, and will probably find the bug that "bit" Mr Smith. The most important element of a readable programming style is the use of white space. I personally can't stand the K&R style because I get visually confused when I read it. It's similar to an English paragraphing that doesn't use indenting or spaces between paragraphs. In the C book itself, this isn't bad, because the program fragments are small and the structures are simple. In real programs, however, there are lots of programs which are unreadable until passed through "indent" (on 4.2). Chris Shaw watmath!watmum!cdshaw or cdshaw@watmath University of Waterloo In doubt? Eat hot high-speed death -- the experts' choice in gastric vileness !