C bites / programming style
Richard L. Klappal
rlk at chinet.UUCP
Sun Sep 8 05:57:12 AEST 1985
In article <209 at 3comvax.UUCP> mikes at 3comvax.UUCP (Mike Shannon) writes:
>
>With regard to changing
>
> if(condition) { | if(condition)
> s1; into {
> s2; | s1;
> } | s2;
> | }
>
>[the idea is to indent the braces so that they are in the same column as
> the statements they enclose]
>
> Why do you like this style? This seems to indicate that
>the braces are associated in your mind with the enclosed statements.
> In my mind, the braces are associaed with the 'if' statment, and
>so they should be indented at the same column as the 'if'. I look for
>the closing brace in the same column to be a sort of 'statement terminator'
>(i.e. when I see it, I think "Ah, the end of the if statement").
> I've seen this unusual indentation style before, and I'm curious
>if you developed a preference for it in learning some other language?
>For some reason, I find this style to be especially hard to read. Anybody
>else feel the same way?
>--
> Michael Shannon {ihnp4,hplabs}!oliveb!3comvax!mikes
Personally, I use the second construct you illustrated only
in PL/I, reason being that the list output from the compiler
shows the indent level in this format, E.i.:
b: if (cond) then
c: do;
c: stmts;
c: end;
b: more stmts;
where the b:, c: represent the indent level.
In C, the cb program outputs statements in the style of your
first example, or (again my preference):
if (cond)
{
stmts;
}
I generally try adapting my coding style to the debugging/style
aids are available on the system/language I which I have to work.
I may not agree entirely with the way those aids put things,
but when I have to repair/update someone elses code, one pass
thru the PrettyPrinter puts that code into my style.
--
Richard Klappal
UUCP: ..!ihnp4!chinet!uklpl!rlk | "Money is truthful. If a man
MCIMail: rklappal | speaks of his honor, make him
Compuserve: 74106,1021 | pay cash."
USPS: 1 S 299 Danby Street |
Villa Park IL 60181 | Lazarus Long
TEL: (312) 620-4988 | (aka R. Heinlein)
-------------------------------------------------------------------------
More information about the Comp.lang.c
mailing list