Path: utzoo!attcan!uunet!lll-winken!lll-lcc!ames!mailrus!uflorida!novavax!twwells!bill From: bill@twwells.uucp (T. William Wells) Newsgroups: comp.lang.c Subject: Always use braces (was: Suggested new C loop syntax) Message-ID: <271@twwells.uucp> Date: 23 Dec 88 11:06:17 GMT References: <5@rsoft.UUCP> <1071@goofy.megatest.UUCP> <861@quintus.UUCP> <3049@arcturus> <2485@ficc.uu.net> <264@twwells.uucp> <8@estinc.UUCP> Reply-To: bill@twwells.UUCP (T. William Wells) Organization: None, Ft. Lauderdale Lines: 44 Summary: Expires: Sender: Followup-To: Distribution: Keywords: In article <8@estinc.UUCP> fnf@estinc.UUCP (Fred Fish) writes: : Since this is my pet peeve #1 about C style, I couldn't resist. There : is no ambiguity if you simply make it a habit to ALWAYS include braces : for {if, while, do, for} etc, even when they are not strictly necessary. Absolutely. One should always include optional braces. There are two advantages: 1) A decrease in the likelyhood of programming errors. 2) An increase in the readability of the program. One should also never write a compound statement on the same line as the head of the statement it is embedded in. E.g., instead of: for (a; b; c) statement; one should write: for (a; b; c) { statement; } Doing that makes finding the statement quite a bit easier. : I was recently helping out a freshman CS major with her C homework and : found out, to my horror, that the teacher in the course was marking : off points for code which included braces when they weren't strictly : required. They were teaching her to write code like: : : inchar = getchar (); : while (inchar != EOF) : if (inchar == 0) : goto done; : else : inchar = getchar (); : done: return inchar; : : Ickkk!!! Double Ickkkk!!!! A goto where a break would have done. --- Bill {uunet|novavax}!proxftl!twwells!bill