Wiki Coding Style: Tabs vs. Spaces
Wiki Coding Style: Tabs vs. Spaces
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).
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).
Every good solution is obvious once you've found it.
Re: Wiki Coding Style: Tabs vs. Spaces
#%^$ 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.
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.
Re: Wiki Coding Style: Tabs vs. Spaces
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.
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 ?
Re: Wiki Coding Style: Tabs vs. Spaces
I voted spaces. Normally I code using tabs, but they really are a pain in the neck to write in browsers.
Re: Wiki Coding Style: Tabs vs. Spaces
Hi,
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
Tabs are faster for editing. Consider assembly: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 ?
Code: Select all
mov foo, bar ;Comment
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.
Re: Wiki Coding Style: Tabs vs. Spaces
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.Imagine your cursor is at the end of "bar" and you want to move the cursor to the start of the comment.
If a trainstation is where trains stop, what is a workstation ?
Re: Wiki Coding Style: Tabs vs. Spaces
You press 'w' exactly once.Brendan wrote: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...Code: Select all
mov foo, bar ;Comment
/me hopes to have started a vi vs. emacs discussion. Popcorn!
Re: Wiki Coding Style: Tabs vs. Spaces
Hi,
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
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.
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.Kevin wrote:You press 'w' exactly once.
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.
- xenos
- 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
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:
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.
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.
};
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.
Re: Wiki Coding Style: Tabs vs. Spaces
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.
Edit: this browser sucks.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
Re: Wiki Coding Style: Tabs vs. Spaces
The problem with TAB indent is:
With space it's always aligned, not always for TAB.
Code: Select all
foo = func ( para1,
para2,
para3 );
-
- Posts: 10
- Joined: Mon Jun 27, 2011 3:34 pm
Re: Wiki Coding Style: Tabs vs. Spaces
I would say tab, but tabs don't work in my browser.
Sorry Linker, but your function is in another file!
Re: Wiki Coding Style: Tabs vs. Spaces
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 ?Chandra wrote:Personally, I'd invest time getting myself a cup of coffee, than having required to type 4 spaces for indentation
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 ?
Re: Wiki Coding Style: Tabs vs. Spaces
Oh just use a pretty printing script for the wiki already :p.
- xenos
- 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
That's why I use tabs for indentation, but spaces for alignment:bluemoon wrote:With space it's always aligned, not always for TAB.
Code: Select all
<tab>foo = func ( para1,
<tab><ssppaaaccee>para2,
<tab><ssppaaaccee>para3 );
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.