Page 3 of 5

Re: C coding style

Posted: Wed Jun 29, 2011 7:13 am
by Love4Boobies
Oops, I missed all the discussion that's been going on since I last posted. It seems Solar had already covered the problem with using hard tabs.

Re: C coding style

Posted: Wed Jun 29, 2011 12:04 pm
by Brynet-Inc
Tabs > Spaces.

Re: C coding style

Posted: Wed Jun 29, 2011 12:43 pm
by Neolander
*distributing pop corn*

Re: C coding style

Posted: Wed Jun 29, 2011 1:41 pm
by NickJohnson
I think the whole tabs/spaces thing is largely irrelevant, as long as tabs are not used for anything other than indentation. When you use tabs to align things, like comments, the tab width can be important (as Love4Boobies pointed out.) However, when they are used for indents, the worst that can happen is that someone with larger tab widths will have some lines exceed the screen width. Also, if tabs are only used at the beginning of the line, using a regular expression to switch tabs with spaces and vice versa becomes trivial, so such decisions can be reversed. So... we shouldn't argue about it.

I prefer tabs in my own code, assuming no other precedent. However, since tabs cannot be typed directly into a web browser text box, using spaces for wiki code is the obvious choice for this situation.

Re: C coding style

Posted: Wed Jun 29, 2011 1:49 pm
by Owen
Tabs for indents will cause misalignments of anything indented which is aligned

Re: C coding style

Posted: Wed Jun 29, 2011 2:20 pm
by Brynet-Inc
berkus wrote:
Brynet-Inc wrote:Tabs > Spaces.
Please, how will you enter them into the wiki? I'm interested.
Write the code in a text editor, compile test it, and then paste it. Surely nobody sane writes code directly on the Wiki.

I use a combination of tabs and spaces, but it is common courtesy to adapt the style of the project you're currently working on.. OpenBSD's KNF works for me.

Re: C coding style

Posted: Wed Jun 29, 2011 3:10 pm
by Kevin
NickJohnson wrote:I think the whole tabs/spaces thing is largely irrelevant, as long as tabs are not used for anything.
There, fixed that for you. ;)

Re: C coding style

Posted: Wed Jun 29, 2011 5:29 pm
by Darwin
NickJohnson wrote:I think the whole tabs/spaces thing is largely irrelevant, as long as tabs are not used for anything other than indentation...
As far as tabs and spaces go, this makes the most sense to me.

Re: C coding style

Posted: Wed Jun 29, 2011 6:22 pm
by Chandra
Brynet-Inc wrote:
berkus wrote:
Brynet-Inc wrote:Tabs > Spaces.
Please, how will you enter them into the wiki? I'm interested.
Write the code in a text editor, compile test it, and then paste it. Surely nobody sane writes code directly on the Wiki.
+1.

Re: C coding style

Posted: Thu Jun 30, 2011 12:00 am
by Solar
Darwin wrote:
NickJohnson wrote:I think the whole tabs/spaces thing is largely irrelevant, as long as tabs are not used for anything other than indentation...
As far as tabs and spaces go, this makes the most sense to me.
Sadly enough, not really.

One, it is far too easy to "forget" that tabs should be used only for indents. Point in case, statements spread over multiple lines:

Code: Select all

// Assuming a TAB display width of 4
int main( int argc, char * argv[] )
{
>---// somewhat constructed, but you know what I mean
>---for ( int i = 0;
>---      i < n;   // #1
>---      ++i )   // #2
>---{
>--->---// BODY
How easy is it to hit TAB twice at #1 and #2? How difficult to detect? How detrimental for layout should someone change the TAB representation width? (Above example isn't exactly great for that, but I didn't want to invest creativeness for the sake of an example right now.)

Two, not all tools support setting arbitrary TAB widths comfortably, if at all. Source isn't watched only in your favourite editor. You use 'less', 'diff', or whatever diff your VCS GUI of choice provides. More epecially, you cannot set TAB widths in the browser. You're advocating a 8-column indent? Really?

Three, we're talking about a Wiki style guide. Firing up a seperate text editor (and setting it to proper TAB handling if it's set to expand tabs by default) is a bit ridiculous. Alternatively, I could of course copy&paste existing tabs for proper indenting... You've got to be kidding me.

Do we really need to have a vote on this? :oops:

PS: Edited a wee bit. I got carried away at one point.

Re: C coding style

Posted: Thu Jun 30, 2011 1:40 am
by Combuster
Do we really need to have a vote on this?
No we don't. Discussions of personal preference have already been excluded from changing the proposed style guide. :twisted:

Re: C coding style

Posted: Thu Jun 30, 2011 2:34 am
by Love4Boobies
It seems I'll have to go pedantic on you :) Misalignment is not the only problem with tabs. Using them results in undefined behavior according to the C standard, as they are not guaranteed to be part of the source character set (unlike for the execution character set). There, your code is not only aesthetically volatile, but also invalid.
Combuster wrote:
Do we really need to have a vote on this?
No we don't. Discussions of personal preference have already been excluded from changing the proposed style guide. :twisted:
Except the style guide is more or less the preferences Solar and you had, just that no one really cared to impose their own. :P

Re: C coding style

Posted: Thu Jun 30, 2011 2:50 am
by quok
Love4Boobies wrote:
Combuster wrote:
Do we really need to have a vote on this?
No we don't. Discussions of personal preference have already been excluded from changing the proposed style guide. :twisted:
Except the style guide is more or less the preferences Solar and you had, just that no one really cared to impose their own. :P
Ahem, I gave my preferences.They just happened to be aligned with what Solar and Combuster were saying. :)

Re: C coding style

Posted: Thu Jun 30, 2011 3:09 am
by Solar
Love4Boobies wrote:Misalignment is not the only problem with tabs. Using them results in undefined behavior according to the C standard, as they are not guaranteed to be part of the source character set (unlike for the execution character set). There, your code is not only aesthetically volatile, but also invalid.
As much as I would have loved that argument to be true :twisted: , it isn't. (Yes, I immediately whipped up my copy of the C99 standard.)

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).
Combuster wrote:Except the style guide is more or less the preferences Solar and you had, just that no one really cared to impose their own. :P
Guilty as charged.

However (as Fanael rightly pointed out), a style guide is mostly about getting it over with... It's a big part about getting code that can be read with relative ease, and - in our special case of a Wiki full of tutorials and code examples for newcomers - another big part about teaching those newcomers some code style that won't make them the "ugly code style pariahs" in a pro development team.

I've worked on "trailing brackets" teams, and while I prefer the additional optical help of vertically-aligned brackets would've gone along with that. (It's a style mostly seen in the Java departments, and usually shunned by C/C++ departments, but there you are.) I've seen lots of "no padding spaces" code, and while disagreeing with that style as far as readability is concerned, would have gone along with that, too. Since I went into the role of "benign dictator" here, I naturally went with my preferences - not before checking that the issue at large still isn't "decided" in the web, and that I'm not pushing a fringe minority opinion.

But unfortunately the subject that's still discussed is the subject of TAB indents - which, in the context of the Wiki, has two clear cons IMHO (too-big indents and not being able to type a TAB in the browser editor) while offering no pros (as you cannot set TABs to your preference in the browser).

While I can somewhat see the benefit of compile-testing your code before posting, consider what happens if you want to convert an already-existing piece of code to TAB indenting: You'd have to copy the code into a different editor, convert there, then copy back... instead of fixing in-place. (Or using the copy&paste approach...) It's just highly impractical.

However, being pushy about a subject doesn't help. I've fielded my arguments against TABs, and will shut up now.

Re: C coding style

Posted: Thu Jun 30, 2011 3:30 am
by Love4Boobies
Solar wrote:
Love4Boobies wrote:Misalignment is not the only problem with tabs. Using them results in undefined behavior according to the C standard, as they are not guaranteed to be part of the source character set (unlike for the execution character set). There, your code is not only aesthetically volatile, but also invalid.
As much as I would have loved that argument to be true :twisted: , it isn't. (Yes, I immediately whipped up my copy of the C99 standard.)

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).
Oops, I got excited for nothing :) That sentence starts with "Both the basic source and basic execution character sets"