On 2013-01-14 22:31, mist wrote:
That guy has rather weird sense of beauty... My eyes started bleeding at the
"Spacing" section.


I sympathize. He posted the worse code excerpt to prove his point. :)

I used to also do "column alignment" in the C code I wrote in the past, but using spaces and not tabs. Used it for initializing arrays of structs, for defining a series of bit masks (I bet you have nothing against this use), but also for a series of function pointer typedefs, for comments and sometimes for cases in a switch statement.

I think it adds readability when you compare similar lines and you don't even need syntax highlighting -- as long as the columns are kept narrow (but wide enough, so that you don't have to push all things whenever you add a line).

The columns idea is mentioned in the file CodeStyleConventions.doc used by idSoftware, which he links on that page. Here are some of the conventions:


> Use real tabs that equal 4 spaces.
Huh? No tabs, ever!. They usually mess up code posted on webpages.

> Pad parenthesized expressions with spaces:
> if ( x ) {}  Instead of  if (x) {}  And
> x = ( y * 0.5f );  Instead of  x = (y * 0.5f);
I agree that it's readable, even more so with functions:
someFunction( parameter1, parameter2 ).method( something );

> Function names start with an upper case:
> void Function( void );
Say what?!

> Typedef names use the same naming convention as variables,
> however they always end with "_t".
> typedef int fileHandle_t;
Now, this is completely reversed...

> Use ‘const’ as much as possible.
Yes, generally good.


> Indent the names of class variables and class methods to make nice columns.
> The variable type or method return type is in the first column and the
> variable name or method name is in the second column.
>
> class idVec3 {
>     float           x;
>     float           y;
>     float           z;
>     float           Length( void ) const;
>     const float *   ToFloatPtr( void ) const;
> }
>
> The * of the pointer is in the first column because it improves readability
> when considered part of the type.

Generally yes, but I can't agree with * being with the type, unless there's always just one variable per line or we're writing in D, for example.






Reply via email to