Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Code Style

Name: Anonymous 2010-01-24 16:09

The following program demonstrates your tab width, indentation style, and various other aspects of your code style. Please write it (in verbatim) in your preferred style. Remember to use spaces instead of tabs, as shitchan automatically converts tabs into 3 space characters.

[code]#include "stdio.h"

int main (void)
{   int   x;
    char  c = 'a';
    float y = 0;
   
    for (x = 0; x < 10; x++)
    {   if  (x % 2 == 0)
            printf ("%d\n", x);
        else
        {   printf ("%c\n", c);
            c +=1;
        }
    }
   
    return 0;
}

Name: Anonymous 2010-01-25 20:40

Oh god, so many hideous code styles. The only one remotely passable is >>31, and it has the legacy compatibility limitations of old K&R, such as requiring the open brace of a function on a newline. >>29 actually isn't terrible, except for the fact that his spacebar seems to be broken.

As the author of >>60, I feel I must educate furthur as to the one true style. There's lots of stuff this did not cover:

double braces around assignment in if statements
if ((x = 7)) do_some_shit();

related declarations should have equal signs aligned
int something      = 4;
int something_else = 7;


repeated related function calls should have arguments aligned (with space only after the commas, none trailing; no alignment of commas or closing brace)
some_func(an_arg,      another_arg);
some_func(a_third_arg, last_arg);


braces can be used around and in ternary operator when needed, and put spaces around ? and : (but never inside braces). usually put braces around arms when needed to clarify, even when the precedence order would allow no braces (mainly because the inner arm of ?: breaks the precedence order)
some_func(a ? (b + c) : d, e);

if an else block needs braces, add braces for the if block as well (don't do like OP). they don't add any lines in this case.
if (x % 2 == 0) {
  printf ("%d\n", x);
} else {
  printf("%c\n", c);
  c = c + 1;
}


no line length limits; this isn't the stone ages. but be reasonable. repeated related function calls however can break the 'reasonable' limitation, and run well over 200 characters; scrolling horizontally to see a table of well-aligned function calls is much preferable to 30 lines of repeated function calls with no alignment to show you the argument layout.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List