Path: utzoo!attcan!uunet!vsedev!logan From: logan@vsedev.VSE.COM (James Logan III) Newsgroups: comp.lang.c Subject: Re: Standard Indentation etc. Message-ID: <1287@vsedev.VSE.COM> Date: 17 Dec 88 02:46:34 GMT References: <663@htsa.uucp> <832@husc6.harvard.edu> <22249@apple.Apple.COM> <5358@boulder.Colorado.EDU> <5181@bsu-cs.UUCP> Reply-To: logan@vsedev.VSE.COM (James Logan III) Organization: VSE Software Development Lab Lines: 73 In article <5181@bsu-cs.UUCP> dhesi@bsu-cs.UUCP (Rahul Dhesi) writes: # Over-indentation eats up precious space. Try this: # # switch (expression) { # case 'a': /* lots of space here for a comment */ # statement # ... # break; # case 'b': # statement # ... # break; # } /* switch */ # # Having each 'case' keyword aligned with the initial 'switch' keyword is # similar to having 'else' aligned with 'if'. We create a comb, and pack # the C code in the gaps. I agree. I used to indent like this: switch (exp) { case 'a': stmt; stmt; break case 'b': stmt; stmt; break; } Until I ran into problems when building finite-state machines that required nested switch statements. Once I stopped indenting the "case" keywords I realized that I liked the way it looks better too. I see some alternate forms of indentation as inconsistent with the way braces are used in function declarations. An example follows: func() { for (;;) { stmt; stmt; } } I would probably use braces beneath and at the same level as the "for", but when I learned C many years ago I got used to the K&R style and have used it ever since. I do format long printf() statements strangely, but I think it makes sense and is consistent with the usage of braces in C. This fprintf() doesn't have a particularly long string, but it exemplifies my meaning: if ((infd = fopen(filename, "w")) == (FILE *)NULL) { fprintf( stderr, "%s: cannot open ", myname ); perror(filename); exit(1); } -- Jim Logan logan@vsedev.vse.com (703) 892-0002 uucp: ..!uunet!vsedev!logan inet: logan%vsedev.vse.com@uunet.uu.net