OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 3:11 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 35 posts ]  Go to page 1, 2, 3  Next

Should the Wiki Coding Style use tabs or spaces for indentation?
Poll ended at Wed Jul 06, 2011 8:13 am
tabs 35%  35%  [ 13 ]
spaces 65%  65%  [ 24 ]
Total votes : 37
Author Message
 Post subject: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Fri Jul 01, 2011 8:13 am 
Offline
Member
Member
User avatar

Joined: Thu Nov 16, 2006 12:01 pm
Posts: 7612
Location: Germany
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.


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Fri Jul 01, 2011 11:30 pm 
Offline

Joined: Thu Jun 09, 2011 2:47 am
Posts: 14
Location: Calif.
#%^$ 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.


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Sat Jul 02, 2011 1:38 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Sat Jul 02, 2011 1:54 am 
Offline
Member
Member
User avatar

Joined: Thu Dec 21, 2006 3:03 am
Posts: 1029
Location: Hobart, Australia
I voted spaces. Normally I code using tabs, but they really are a pain in the neck to write in browsers.

_________________
My Personal Blog | My Software Company - Loop Foundry | My Github Page


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Sat Jul 02, 2011 6:04 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
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:
    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.


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Sat Jul 02, 2011 6:41 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Sat Jul 02, 2011 7:25 am 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1070
Location: Germany
Brendan wrote:
Code:
    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)


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Sat Jul 02, 2011 8:05 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
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.


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Sat Jul 02, 2011 9:02 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 11, 2005 11:00 pm
Posts: 1110
Location: Tartu, Estonia
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:
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


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Sat Jul 02, 2011 9:04 am 
Offline
Member
Member
User avatar

Joined: Sat Jul 17, 2010 12:45 am
Posts: 487
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 !


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Sat Jul 02, 2011 4:17 pm 
Offline
Member
Member
User avatar

Joined: Wed Dec 01, 2010 3:41 am
Posts: 1761
Location: Hong Kong
The problem with TAB indent is:
Code:
foo = func ( para1,
             para2,
             para3 );


With space it's always aligned, not always for TAB.


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Sat Jul 02, 2011 4:46 pm 
Offline

Joined: Mon Jun 27, 2011 3:34 pm
Posts: 10
I would say tab, but tabs don't work in my browser.

_________________
Sorry Linker, but your function is in another file!


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Sat Jul 02, 2011 5:40 pm 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Sat Jul 02, 2011 8:47 pm 
Offline
Member
Member

Joined: Sat May 07, 2011 8:21 am
Posts: 32
Oh just use a pretty printing script for the wiki already :p.


Top
 Profile  
 
 Post subject: Re: Wiki Coding Style: Tabs vs. Spaces
PostPosted: Sun Jul 03, 2011 1:18 am 
Offline
Member
Member
User avatar

Joined: Thu Aug 11, 2005 11:00 pm
Posts: 1110
Location: Tartu, Estonia
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:
<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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 35 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group