Wiki Coding Style: Tabs vs. Spaces

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.

Should the Wiki Coding Style use tabs or spaces for indentation?

Poll ended at Wed Jul 06, 2011 8:13 am

tabs
13
35%
spaces
24
65%
 
Total votes: 37

User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Wiki Coding Style: Tabs vs. Spaces

Post by Solar »

When the arguments have all been said, have a count of hands and be done with it.

The somewhat lengthy discussion is here. If you haven't taken part in it, well, your bad - it's more or less closed now (I hope). 8)
Every good solution is obvious once you've found it.
drew
Posts: 14
Joined: Thu Jun 09, 2011 2:47 am
Location: Calif.

Re: Wiki Coding Style: Tabs vs. Spaces

Post by drew »

#%^$ it!! I admit it's just a pain in the @$$ to have to hit space 4 times to make a stupid indentation. it should be a tab. your operating systems should be programmed to display them okay. make a standard on the width of the tabs. why would I press a space bar four times, when I could press a tab bar once?? it makes no sense to use space bars.

I mean... honestly... it's not that hard to make an editor that would automatically resolve the tab issue.

what? that doesn't make sense to you??

well imo, making an editor that calculates widths automatically makes a lot more sense than using spaces as indentations.

have none of you honestly thought of that??

it's practically part of the syntax for anyone that cares...

you can make your silly standard, but you can't make my follow it.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Wiki Coding Style: Tabs vs. Spaces

Post by gerryg400 »

Are you serious ? You're not serious are you ? I don't know what editor you use but when I hit tab in my editor it indents to the next tab marker by inserting spaces.

I just can't understand the tab versus space thing. Lots of people have given reasons for using spaces instead of tabs. But, has anyone been able to provide a single reason for using tabs ?

Surely this is the least interesting part of the coding style guide. It's quite amazing that it's the one thing we argue about.
If a trainstation is where trains stop, what is a workstation ?
User avatar
JackScott
Member
Member
Posts: 1031
Joined: Thu Dec 21, 2006 3:03 am
Location: Hobart, Australia
Contact:

Re: Wiki Coding Style: Tabs vs. Spaces

Post by JackScott »

I voted spaces. Normally I code using tabs, but they really are a pain in the neck to write in browsers.
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Wiki Coding Style: Tabs vs. Spaces

Post by Brendan »

Hi,
gerryg400 wrote:I just can't understand the tab versus space thing. Lots of people have given reasons for using spaces instead of tabs. But, has anyone been able to provide a single reason for using tabs ?
Tabs are faster for editing. Consider assembly:

Code: Select all

    mov foo, bar                          ;Comment
Imagine your cursor is at the end of "bar" and you want to move the cursor to the start of the comment. In a perfect world it'd be like modern wordprocessors, with tab stops at arbitrary positions (recorded in the file's header), and you'd only need to press "right cursor" key once. Unfortunately the plain text file format has no header so a text editor can't support that; and you end up with maybe 5 tabs where you have to press the "right cursor" key 5 times. It's crappy, but it could be worse...

Now consider spaces - do you want to press the "right cursor" key 20 times? Is it faster to press the "end" key and use then "left cursor" key? Is it faster to shift your hand from the keyboard to the mouse (and back), and try to position the cursor using the mouse pointer? Regardless of how you do it, it's going to suck more than pressing the "right cursor" key 5 times (and suck a lot more than pressing it once).

For C it's a similar problem, except that it's more often at the start of the line.

Of course we're not talking about normal code - we're talking about HTML pages. For HTML pages, you shouldn't be using tabs or spaces - you should use "non-breaking space" (Unicode codepoint U+0000A0), or if that isn't supported properly (if the page isn't using a Unicode character encoding, or if some web browsers don't support it properly) then you should fall back to the old " " HTML sequence.

Of course we're not talking about normal HTML - we're talking about the WIki. It'd be nice if the Wiki automatically replaced spaces in code sections (and potentially tabs too) with "non-breaking space". Unfortunately it doesn't. I'm not too sure if the Wiki handles Unicode properly (but I'm certain it won't like " " in source code examples).


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.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Wiki Coding Style: Tabs vs. Spaces

Post by gerryg400 »

Imagine your cursor is at the end of "bar" and you want to move the cursor to the start of the comment.
I hold the option key, press the right arrow key then press the left arrow key. I'm using eclipse but even editors as old as vi have that type of navigation facility.
If a trainstation is where trains stop, what is a workstation ?
Kevin
Member
Member
Posts: 1071
Joined: Sun Feb 01, 2009 6:11 am
Location: Germany
Contact:

Re: Wiki Coding Style: Tabs vs. Spaces

Post by Kevin »

Brendan wrote:

Code: Select all

    mov foo, bar                          ;Comment
Imagine your cursor is at the end of "bar" and you want to move the cursor to the start of the comment. In a perfect world it'd be like modern wordprocessors, with tab stops at arbitrary positions (recorded in the file's header), and you'd only need to press "right cursor" key once. Unfortunately the plain text file format has no header so a text editor can't support that; and you end up with maybe 5 tabs where you have to press the "right cursor" key 5 times. It's crappy, but it could be worse...
You press 'w' exactly once.

/me hopes to have started a vi vs. emacs discussion. Popcorn!
Developer of tyndur - community OS of Lowlevel (German)
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Wiki Coding Style: Tabs vs. Spaces

Post by Brendan »

Hi,
gerryg400 wrote:I hold the option key, press the right arrow key then press the left arrow key. I'm using eclipse but even editors as old as vi have that type of navigation facility.
Kevin wrote:You press 'w' exactly once.
So, is the standard for all text editing (including all text editors, all word-processors, text input boxes in web browsers, etc) "hold the option key, press the right arrow key then press the left arrow key" or is the standard "press 'w' exactly once"? I tried both methods in Kwrite and neither worked; then I tried both methods in notepad++ and neither worked; therefore you're both wrong.

Maybe we've just got an inadequate file format (plain text), combined with idiotic/non-standard hacks as work-arounds that attempt to make up for problems with the inadequate file format.

When one design failure isn't enough, try lots of design failures... :)


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
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Wiki Coding Style: Tabs vs. Spaces

Post by xenos »

Brendan, I totally agree with you. For code examples in HTML pages the non-breaking space is probably the best character for indentation and alignment and it would be great if the Wiki supports it (I have not checked that yet).

Personally, I use tabs for indentation and spaces for alignment:

Code: Select all

struct mystruct
{
<tab>int myvar;<sssppppaaacccceee>// Always 0.
<tab>int my_long_named_var;<space>// Never 0.
};
The tab count at the beginning of each line is equal to the indentation depth - it is independent from the preference on visual indentation, i.e., whether indentation levels should be separated by 2 spaces, 4 spaces, 8 spaces... If you open the code in an editor, you can set the tab width to anything you like. If you don't like what you see, you misconfigured your text editor. If your text editor doesn't support configuring the tab width, you're using the wrong editor.

Of course alignment should be independent of editor settings, so I use spaces for this purpose. No matter which tab width I use, the two comments from my example will always be aligned.

So the question remains: how would I align things which are at different indentation levels? Simple answer: I don't. In my code, each aligned block of comments, variables or whatever belongs to only one indentation level. For me there is simply no need to align comments across indentation levels.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Wiki Coding Style: Tabs vs. Spaces

Post by Chandra »

I vote for tabs because I feel comfortable with it. Personally, I'd invest time getting myself a cup of coffee, than having required to type 4 spaces for indentation. And I know very well that majority of people here, are against this.

Edit: this browser sucks.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Wiki Coding Style: Tabs vs. Spaces

Post by bluemoon »

The problem with TAB indent is:

Code: Select all

foo = func ( para1,
             para2,
             para3 );
With space it's always aligned, not always for TAB.
CommunistPancake
Posts: 10
Joined: Mon Jun 27, 2011 3:34 pm

Re: Wiki Coding Style: Tabs vs. Spaces

Post by CommunistPancake »

I would say tab, but tabs don't work in my browser.
Sorry Linker, but your function is in another file!
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Wiki Coding Style: Tabs vs. Spaces

Post by gerryg400 »

Chandra wrote:Personally, I'd invest time getting myself a cup of coffee, than having required to type 4 spaces for indentation
Chandra, doesn't your editor have a mode where it will enter 4 (or the appropriate number for alignment) spaces when you press the tab key ?

To the guys who say they prefer tabs, I also press tab to indent my code and to align comment blocks etc. I'm sure I type into my editor in almost the same way as the 'tab' guys. It's just that my editor converts them to spaces

We are not voting here which key on the keyboard should be used for entering the whitespace that formats our code (for that I vote tab), we are voting on which character should be stored in the actual source files on the wiki ?
If a trainstation is where trains stop, what is a workstation ?
schilds
Member
Member
Posts: 32
Joined: Sat May 07, 2011 8:21 am

Re: Wiki Coding Style: Tabs vs. Spaces

Post by schilds »

Oh just use a pretty printing script for the wiki already :p.
User avatar
xenos
Member
Member
Posts: 1121
Joined: Thu Aug 11, 2005 11:00 pm
Libera.chat IRC: xenos1984
Location: Tartu, Estonia
Contact:

Re: Wiki Coding Style: Tabs vs. Spaces

Post by xenos »

bluemoon wrote:With space it's always aligned, not always for TAB.
That's why I use tabs for indentation, but spaces for alignment:

Code: Select all

<tab>foo = func ( para1,
<tab><ssppaaaccee>para2,
<tab><ssppaaaccee>para3 );
I know it looks cumbersome, but afaik it's the only way to both 1. keep aligned stuff always aligned, independent of tab width and 2. adjust the width of indentation levels to whatever your preference is, simply by changing the tab width setting of your editor. (Except using a code formatter, of course.) If anyone knows a better method to achieve these two goals, please let me know.

Besides, I set up Kate to show visible tab markers, so one can easily distinguish between tabs and spaces, and read off the indentation level by just counting tab markers. Yes, I know, there is also an option to show visible indentation lines. It's just my personal preference, not a general recommendation or even a standard proposal.
Programmers' Hardware Database // GitHub user: xenos1984; OS project: NOS
Post Reply