Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site cincy.UUCP Path: utzoo!linus!philabs!cmcl2!floyd!harpo!eagle!mhuxl!ihnp4!cbosgd!qusavx!cincy!jreuter From: jreuter@cincy.UUCP (Jim Reuter) Newsgroups: net.unix,net.lang.c Subject: typedefs, etc. Message-ID: <1165@cincy.UUCP> Date: Tue, 27-Dec-83 18:19:04 EST Article-I.D.: cincy.1165 Posted: Tue Dec 27 18:19:04 1983 Date-Received: Fri, 30-Dec-83 00:24:10 EST References: <2035@fortune.UUCP>, <2466@azure.UUCP> Organization: U. of Cincinnati ECE Lines: 81 I agree with almost everything Steve Summit (azure!stevesu) has to say about typedefs, readability, and other things, but I strongly disagree with the following statement: ... I once had points taken off on a programming assignment for writing something like if(a == b) return(TRUE); else return(FALSE); The grader said I should have "more succinctly" said return(a == b); I realize now that he was wrong, and I wish I'd realized it then, and called him on it. He was obviously a fully indoctrinated member of the "hacks are beautiful" school. Those two fragments do do the same thing, and this is a case where the second one might even generate slightly more efficient code. But I have to look at something like "return(a == b)" twice or even three times to convince myself that it's identical to what I conceptualize as "if a equals b it's true, otherwise it's not." Why make things difficult? I know the idiom, and it still gets in my way. ... I think his confusion may arise from the fact that in C, boolean values are integers. In some programming languages, booleans are completely separate from integer types, and one can declare a function of boolean type that will return TRUE or FALSE as the result of a boolean (comparison) operation. In fact, this is just what boolean operators are. Perhaps if he used the much discussed typedef, and wrote typedef int BOOL; BOOL somefunc( a, b ) int a,b; { return( a == B ); } things would seem clearer. I disagree with his statement that his first example is clearer, and I can show several examples of similar constructs which are definitely NOT clearer: c = a > b ? a : b; is worse than #define max(a,b) (a > b ? a : b) c = max( a, b ); or perhaps if (i == 5) i = 6; if (i == 4) i = 5; if (i == 3) i = 4; if (i == 2) i = 3; if (i == 1) i = 2; is far worse than i = i + 1; or even i++; This last example I saw three years ago in an article about some programming atrocities that real, practicing, "professional programmers" were commiting. It was written by a manager of a programming staff. I realize it is a bit extreme, but it is of the same style.