Re: C coding style
Posted: Mon Jun 27, 2011 3:52 am
Yep. No comma operator.Love4Boobies wrote:As for the asterisk thing, the following might look a bit odd:Code: Select all
int * a, * b, * c;
Yep. No comma operator.Love4Boobies wrote:As for the asterisk thing, the following might look a bit odd:Code: Select all
int * a, * b, * c;
Code: Select all
else {
Code: Select all
switch( c ) {
Code: Select all
if ( a == *b )
Code: Select all
while( ( c = getchar() ) != EOF )
Code: Select all
if (
Code: Select all
while(
Code: Select all
struct foo *bar = malloc(sizeof *foo);
size_t int_width = sizeof (int);
If you use large enough identations (4 spaces and more), you can clearly separate blocks of code visually, and lines with an alone bracket start to feel like void, at least in my experience. Guess it's a matter of habits and opinion.drew wrote:and then not even enough whitespace that makes it MUCH easier to read for the curly brackets?
Care to be more precise ? In my experience, it's tabs which result in a mess when you open the source with an editor that has different tab size.spaces for indentations just makes a giant mess
Frankly, a few kilobytes are negligible nowadays. A single normally-sized picture takes much more space, yet many people love screenshots (me included)., and takes more space for your source code. it's not much, but with 1k lines of code and indentations everywhere, the space they use adds up. it could easily be an extra several kilobytes... that's nothing really... but doesn't it make you sick knowing that something is being wasted? or is our minds not in the maximum-perfectionist-efficiency state of minds?
It's about making it easier to read code. The human mind has the ability to learn and perform things faster when it often encounters the same thing, included code that's formatted in the same way, it's sad not to use this possibility and make every piece of code look different and foreign to the reader.and if it's not, what are we doing trying to reinvent the wheel? and don't even claim not to be a perfectionist in the least, or you wouldn't even be bothering with a standard for code format. it's kind of a paradox from my point of view or more of an oxymoron.
You know, most people just set up their text editor so that TAB adds the right amount of spaces and stop to bother.I'd rather put 10 new lines between each of my functions than have 20 spaces for each indentation I need to make. clearly that's the biggest thing that drives me nuts with the way people format their code. for the love of ASM... stop using your space bar like it's an entire drum set...
Code: Select all
int foo;
double bar;
Code: Select all
int foo;
double bar;
phpBB needs a 'like' or '+1' button. I'd upvote this.berkus wrote:Since we stopped talking about the guide, and started talking about personal preferences, here's my take on parens:
There's no space after function names, e.g. main(
But there's space after reserved words, e.g. while (
Makes it easy to grep. Looks nice.
Believe me or not, I know this. It's just arguing about code style what is pointless and silly.Solar wrote:@ Fanael: Code style arguments have literally destroyed more than one otherwise perfectly good programmer team. Believe it or not, code style is important (as in, find a style and adhere to it, not as in, argue about it all day long).
I find this to be very similar to my own preferences and aside from a few small nitpicky things which I won't bring up, I'm perfectly happy with this style guide. I say we just move it out of Love4Boobies' user space and run with it.Solar wrote: Is there a good reason to not accept this as Wiki Style Guide?
I have no idea what you're talking about.Kevin wrote:...is it intentional that you have a space after if, but not after while?
Code: Select all
for (p = list; p != NULL; p = p->next) <TAB> // hello,
<TAB> printf("%p ", p); <TABS> // world!
Code: Select all
if (a == b) <SPACES1> // hello,
<TAB> c = d; <SPACES2> // world!