Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site peora.UUCP Path: utzoo!linus!decvax!bellcore!petrus!sabre!zeta!epsilon!gamma!ulysses!mhuxr!mhuxt!houxm!vax135!petsd!peora!jer From: jer@peora.UUCP (J. Eric Roskos) Newsgroups: net.lang.c,net.lang Subject: Re: Varieties of conditional statement Message-ID: <1703@peora.UUCP> Date: Tue, 8-Oct-85 17:25:10 EDT Article-I.D.: peora.1703 Posted: Tue Oct 8 17:25:10 1985 Date-Received: Fri, 11-Oct-85 07:18:02 EDT References: <418@phri.UUCP> <2600012@ccvaxa> <1901@reed.UUCP> Followup-To: net.lang Organization: Perkin-Elmer SDC, Orlando, Fl. Lines: 122 Xref: linus net.lang.c:6144 net.lang:1626 > The above difference of opinion has in the past been called a religious > argument, with good reason. Back in the old days, before religion was declared unconstitutional, religious arguments were logical (albeit usually modal). Presently "religious argument" seems to imply "irrational", but actually reason underlies most things, except where, through habit and ignorance, irregularities prevail (and these are the things people argue over endlessly). The different brace styles actually have their basis in a much more fundamental, and presently very important, matter having to do with the design of languages. Some languages, such as Pascal and C, define conditional statements (this includes ifs, whiles, etc) like this: e.g., if (x) You then have defined recursively as either of a simple statement, or as a sequence of statements delimited by a begin/end pair. However, this style has recently fallen into disfavor. Thus we have the sort of definition that is in Ada, in which all conditional statements can contain one or more statements, like this: {} where the conditional itself is imbedded in the conditional begin. Now, I would argue that the latter is a "weaker" construct than the former. The reason is (among other things) that the which can be a compound statement can also have private data (and thus is a "block"), whereas the latter approach requires a separate "block" construct to be defined if you want to have a local scope of reference (and note that syntactically, defining a local scope of reference within each type of conditional is harder since the declarations have to be duplicated in each conditional type). To expand on this, I would argue that a language construct "a" is stronger than two language constructs "b" and "c" if "a" can express everything that both "b" and "c" can express, but "b" cannot express some things "c" can express, or vice versa. I would further argue that a language having two identical ways of expressing the same language construct is weaker than one having only one unique way of expressing the same construct. Clearly, the compound statement can express both the body of a conditional, and a "block" (where, for this discussion, let us define a "block" as a sequence of statements having its own private scope of reference). However, the body of a conditional cannot be a block: because if it is, then it is equivalent to a compound statement; and in this latter case, the language is weaker than a language with only one form of compound statement, because several variations of this equivalent compound statement exist (corresponding to the numbered above). Likewise, a block cannot be the body of a compound statement, unless again there are several synonymous ways of expressing the block, which once again makes the language weaker. Thus I would argue that a language with a unique compound statement, and conditionals of the form " ", is a stronger language than one with the Ada-style of conditionals. Now, this brings us to C. It is my feeling (which is open to interpretation, since it is a sort of meta-semantic one) that writing if (bool) { stmts; } is in a general semantic sense (i.e., looking at the semantics of the coding style, as opposed to those of the language itself) equivalent to writing if (bool) stmts; endif or, alternately, that it is stylistically equivalent to writing c = a + (c + b); as opposed to writing c = a + (c + b); Because, in the latter interpretation, you are writing two distinct syntactic components (the and part of the ) on the same line, but then breaking the latter one (the ) across lines; and in the former, you are "hiding" the opening brace. Neither way seems as stylistically satisfactory as writing the conditional on one line, and then writing the compound statement on the lines below it; it's just a matter of breaking the statement at a point that is most reasonable. As far as whether to indent the braces to the level of the statements that make up the compound statement, or only to the level of the conditional, now THAT is truly a matter of opinion. (Though I think not indenting them aids in finding them). Now, we could go on to argue whether or not data declarations should be indented, and how, but now that I have expressed the above opinion, I will not comment any more; I try to stay out of these debates, due to the tendency of people to write "flames" without reading the original posting they are following up on thoroughly. Besides, my office has meanwhile filled up with 3 assembly-language programmers who are furiously arguing about how they should allocate some registers, and thus it's hard enough to proofread what I have written already. :-) Beware: since the above was more language-theoretic than C-theoretic, I have directed followups to net.lang; you should change this if you are going to discuss only C braces. -- Shyy-Anzr: J. Eric Roskos UUCP: Ofc: ..!{decvax,ucbvax,ihnp4}!vax135!petsd!peora!jer Home: ..!{decvax,ucbvax,ihnp4}!vax135!petsd!peora!jerpc!jer US Mail: MS 795; Perkin-Elmer SDC; 2486 Sand Lake Road, Orlando, FL 32809-7642