C coding style

All about the OSDev Wiki. Discussions about the organization and general structure of articles and how to use the wiki. Request changes here if you don't know how to use the wiki.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: C coding style

Post by Brendan »

Hi,
Solar wrote:According to chapter 5.2.2 of the standard, the source character set includes "control characters representing horizontal tab, vertical tab, and form feed" (whatever good that would do).
I vote for "no vertical tabs allowed" in the style guide! ;)


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: C coding style

Post by Solar »

I wouldn't even know how to enter them... :lol:
Every good solution is obvious once you've found it.
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: C coding style

Post by Kevin »

But we definitely should require a form feed after each function. :D
Developer of tyndur - community OS of Lowlevel (German)
Darwin
Member
Member
Posts: 43
Joined: Sun Jan 16, 2011 6:58 pm
Location: United States

Re: C coding style

Post by Darwin »

I'm not happy.

Image
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: C coding style

Post by Combuster »

Brynet-chan deserves a different title, really. I haven't seen him win any awards. 8)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Brynet-Inc
Member
Member
Posts: 2426
Joined: Tue Oct 17, 2006 9:29 pm
Libera.chat IRC: brynet
Location: Canada
Contact:

Re: C coding style

Post by Brynet-Inc »

Combuster wrote:Brynet-chan deserves a different title, really. I haven't seen him win any awards. 8)
I've gained some notoriety with my ability to kiss @$$, you know what I mean.
Image
Twitter: @canadianbryan. Award by smcerm, I stole it. Original was larger.
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: C coding style

Post by Love4Boobies »

Getting back to the guide:
  • Pointer declarations ( int * a ) vs. dereferencing "( *a ) is a bad idea. The declaration syntax mimics expressions on purpose, I thought we were running away from edge cases. Next thing you know, we're either going to have to do stuff like ! b or char a [MAX]; --- I say we revert this.
  • I can understand the concern regarding the lack of nested comments in C, but this is a wiki; the restriction is kind of silly since we're not going to temporarily turn code off on the wiki.
I'm still pretending that treating sizeof differently than other operators is not an edge case :) The equivalent for addition, according to the current guide should be ( a ) + ( b ).
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: C coding style

Post by Love4Boobies »

The whole purpose of a standard is to be a substitute for common sense (usually, because there is no common sense) :roll:
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: C coding style

Post by Solar »

Well said. 8)
Love4Boobies wrote:Pointer declarations ( int * a ) vs. dereferencing "( *a ) is a bad idea. The declaration syntax mimics expressions on purpose, I thought we were running away from edge cases. Next thing you know, we're either going to have to do stuff like ! b or char a [MAX]; --- I say we revert this.
There is the age-long discussion on int* b (grouping the type, avoiding errors in multiple pointer declarations in a comma-separated declaration list) vs. int *b (declaraction mimics use). I always felt that int * b was deflating that particular argument nicely... are you sure about that revert? You'll get right back into the discussion with any int* b advocates around?!?
I can understand the concern regarding the lack of nested comments in C, but this is a wiki; the restriction is kind of silly since we're not going to temporarily turn code off on the wiki.
I admit that's an artifact of my "general project style" leaking into the Wiki guide. I feel that /* */ is just asking for trouble, and should best be avoided altogether... I removed the two lines advocating // only, but left the example comments in that form - that's better?
I'm still pretending that treating sizeof differently than other operators is not an edge case :) The equivalent for addition, according to the current guide should be ( a ) + ( b ).
Well... sizeof isn't exactly "just like the other operators" to begin with. Unless, of course, you're using and or or. ;-)
Every good solution is obvious once you've found it.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: C coding style

Post by Combuster »

Love4Boobies wrote:I can understand the concern regarding the lack of nested comments in C, but this is a wiki; the restriction is kind of silly since we're not going to temporarily turn code off on the wiki.
But the person who copied from the wiki might.

The fact that it's posted on the wiki only implies stricter rules than normal coding standards: the code needs to work both as web-readable and as actually useful code. Your logic that the wiki doesn't compile code, so let's type "while" with an capital does not make sense.
I admit that's an artifact of my "general project style" leaking into the Wiki guide.
You know, I mentioned that one first. :wink:


In other words, why are we discussing things that are fine as a standard, but troublesome from a religious standpoint?
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: C coding style

Post by Solar »

As if I'd be listening to you. :twisted: 8)
Every good solution is obvious once you've found it.
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: C coding style

Post by Combuster »

Ok, I see. Any resemblance to real persons, living or dead, is purely coincidental. :twisted:
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: C coding style

Post by qw »

Combuster wrote:so let's type "while" with an capital
Have you ever read the source code of the VAL linker? It's a nice piece of software, but the code uses the preprocessor so intensively that it doesn't even look like C anymore:

Code: Select all

#define If      if ((
#define Then    )) {
#define And     ) && (
#define Or      ) || (
#define Else    } else {
#define ElseIf  } else if ((
#define EndIf   }
Talking about coding styles...
User avatar
Love4Boobies
Member
Member
Posts: 2111
Joined: Fri Mar 07, 2008 5:36 pm
Location: Bucharest, Romania

Re: C coding style

Post by Love4Boobies »

Combuster wrote:
Love4Boobies wrote:I can understand the concern regarding the lack of nested comments in C, but this is a wiki; the restriction is kind of silly since we're not going to temporarily turn code off on the wiki.
But the person who copied from the wiki might.
I don't know about you, but most of us here don't agree with copypasta.
The fact that it's posted on the wiki only implies stricter rules than normal coding standards: the code needs to work both as web-readable and as actually useful code. Your logic that the wiki doesn't compile code, so let's type "while" with an capital does not make sense.
I'm not sure writing illegal code helps with readability... People do go to great lengths to make code more readable. There has even been research showing that monospaced fonts are worse for readability but better for actual coding, which is why most textbooks don't use monospaced fonts.
In other words, why are we discussing things that are fine as a standard, but troublesome from a religious standpoint?
K&R was fine as a standard too, until you proposed changes that come from your own religion. :wink: Not that your coding style is bad, but you see my point...

Next, I propose that we use digraphs, trigraphs, and <iso646.h> as much as possible. :lol:
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: C coding style

Post by Solar »

/me knocking the table with the hammer.

"Quiet please! Calm in the Courtroom!"

/me waits for the hubbub to die down.

"Prosecution has read the indictment on the subject of the Wiki Coding Styleguide."

{Some applause from the ranks.}

"Attorneys of Defense have filed objection on the subject of TABs vs. Spaces, and have grumbled about various minor matters without actually voicing (much) protest."

{Some laughter, some grumbling.}

"The subject of tabs vs. spaces is voted for at another place. If there is anyone in attendance who objects to any significant points of the style guide other than the TABs vs. Spaces issue, he may raise his voice now or be quiet forever."

/me glaring at the audience, daring anyone to speak up.

8)
Every good solution is obvious once you've found it.
Post Reply