Tabs or Spaces

Tabs or Spaces

  • Tabs

    Votes: 32 61.5%
  • Spaces

    Votes: 20 38.5%

  • Total voters
    52

KingKaeru

Supreme [H]ardness
Joined
Jul 16, 2000
Messages
6,465
Just wondering what [H] coders go with and why?

Over the years I've switched between both depending on the development shop but personally prefer spaces as it provides the most consistency across editors when aligning code vertically.

<insert smilie beating horse gif> :p
 
Tabs.

- Less characters results in a smaller file size.
- Certain languages depend on tabs as part of their syntax.
- If I'm sharing/receiving code and someone prefers 3 characters of spacing and I prefer 4, but someone else prefers 6 then I don't have to worry about it. My IDE will use 4 (because it's set to 4) and everyone else is free to use their settings.
 
Tabs, I like to hit backspace once to go back one level of indention, not 4x.
 
Whatever my company's coding policy dictates or whatever is necessary to keep consistency with existing code. At the last company, 4 space softtabs. Here, it's 3 space softtabs.

If I'm writing from scratch, I've switched to using 4 space soft tabs over using hard tabs.

But overall, I prefer spaces.
 
Tabs. They exist solely for the purpose of indentation. In addition, you can utilize Shift-Tab to de-indent as opposed to having to switch all the way over to the opposite end of the keyboard to hit backspace (and have to hit it three or four times too, mind you).

While it's true that some editors/viewers like to set tabs at 8 spaces or some Godawful high number of spaces (like the Firefox code viewer), this is the exception rather than the norm. Considering I'd never use any kind of viewer or editor that doesn't let me specify tab length, this is a non-issue for me.
 
Tabs, but any respectable text editor can do either and can emulate tab behavior but save spaces, etc.
 
In addition, you can utilize Shift-Tab to de-indent as opposed to having to switch all the way over to the opposite end of the keyboard to hit backspace
Any decent IDE should allow this to work with spaces. Visual Studio has had it since at least 2005.
 
I like spaces.

And VS can convert all tabs to spaces and probably back to tabs... haven't tried converting leading spaces to tabs though.. so not sure.

I really hate it when I get a piece of code that has tabs and spaces mixed for indentation.

You hit backspace expecting to go back one space and it takes you back 3 or 4. :mad:

I also hate it when you are using an IDE and it decides that it wants to respace everything how it thinks it should be.... VS does this with some web files.. such as .js and .css.
 
Tabs if there's no preference. I'll also change settings in VS or Eclipse as needed.
 
Any decent IDE should allow this to work with spaces. Visual Studio has had it since at least 2005.
My favorite text editors don't, however. Fraise doesn't. Notepad2 doesn't either. It's beyond frustrating.
 
I do 2 space indentations... just what I first learned and was forced to do.

Our instructor actually had a program that would check your code for tabs and you'd lose 10-20 points if you had any. One assignment I made a small change on a school computer before submitting it, I didn't realize it was set to use tabs instead of spaces and I got 20 points off. Booo.

But I figure I'll just use the style guide they give me.
 
Last edited:
Spaces. Tabs default to 8 spaces in a number of programs (windiff, notepad, etc), making using those programs unreadable with tabs. Additionally, any custom alignment dies with spaces.
 
Another lame poll -- which language? What about a mix? It's not uncommon to use a tab for the first indent, then spaces afterward.

Say the vote finishes 30 (for tabs) and 70 (for spaces). What's that tell us? Here's what: a big plate of nothing!
 
Another lame poll -- which language? What about a mix? It's not uncommon to use a tab for the first indent, then spaces afterward.

Say the vote finishes 30 (for tabs) and 70 (for spaces). What's that tell us? Here's what: a big plate of nothing!

Mixing tabs and spaces just seems awkward.

But in the end I think it's just preference / what you're used to. Obviously some languages require tabs and you can't change it for style. But languages like C / C++ you can do whatever you want pretty much.
 
Another lame poll -- which language? What about a mix? It's not uncommon to use a tab for the first indent, then spaces afterward.

Say the vote finishes 30 (for tabs) and 70 (for spaces). What's that tell us? Here's what: a big plate of nothing!

This is important and heretics will burn for choosing incorrectly!

What, tabs vs. spaces seems to make as much sense as any other religion out there :p
 
Depends on the IDE, really.

If I'm in VIM, spaces. If I'm in Visual Studio, tabs. If I'm in Visual Studio but I'm working on a codebase where the other devs use spaces, I'll use spaces.
 
Mostly do Visual C/C++ here, and I prefer tabs for indentation. It's a single keystroke and is easily undone. I like using spaces within function calls and conditional expressions for readability. I treat Java work under Netbeans the same.

For example:
while( ( ch = getchar() ) != EOF )
{ ... }

Works for me better than:

while((ch=getchar())!=EOF)
{...}

Of course being a team player is really important, so I won't force my ways. :)
 
Last edited:
One things for sure: K&R indenting sucks, and always have a block following any control statements.
 
I use tabs mostly because it's faster. What I often do is select a whole chunk of code and I can hit tab or shift+tab to shift the whole block around if needed (ex: just copy and pasted a block into a loop). this works in notepad++ at least. In some editors, it will just erase the code when you try that.
 
I didn't realize tabs were so popular. I use spaces, my IDE converts all my tabs for Java and C in to 4 spaces.

Many projects and companies will have there own requirements as to coding style. For instance chapter 1 of the Linux kernel coding style document deals with indentation and requires 8 spaces. I know several Apache projects have style manuals associated with them as well.
 
Last edited:
Another lame poll -- which language? What about a mix? It's not uncommon to use a tab for the first indent, then spaces afterward.

Say the vote finishes 30 (for tabs) and 70 (for spaces). What's that tell us? Here's what: a big plate of nothing!

Yes the results of the poll will tell us nothing and it really does come down to the style guide for the particular team you're working with anyways.

The poll/thread is meant as a way to bring up discussion on the pros and cons of each. Lets not get our panties in a bunch over nothing :p
 
I'm amassed people would choose spaces over tabs (too many extra keystrokes, RSI). I hope you guys are aware of Crtl+E,D in visual studio (+ most other platforms have a similar tidy function) - once it is configured the way you/ your company likes it, you never have to worry about this again.

What's the next poll? everyone's caffeine intake & Favorite beverage?

They would be far more interesting..
 
I'm amassed people would choose spaces over tabs (too many extra keystrokes, RSI).

A lot of IDE's (including Visual Studio iirc) can be configured to use spaces when you use the tab key, so the the character thing isn't a big deal.
 
Tabs. In many editors, you can set how many spaces the tabs are.
 
4 spaces.

I'd use tabs with a display-width of 4 *if*:

1. All browsers supported a css tab-size property for pre elements like Opera's -o-tab-size property and sites where you post code made use of it.

2. Opera's source editor and mail client (in text/plain composition mode at least) supported adjusting the display width of tabs.

For text editors and IDEs, it's not really an issue using tabs.
 
What's that tell us?

Why, it tells us who is with us, and who is against us!!! So later on the tab lovers can call the space lovers closed-minded Yooks and the space lovers can call the tab lovers self-absorbed Zooks.
 
All depends on what im doing and trying to get at...

As far as indenting goes, defiantly tabs. However if im trying to line up comment sections or trying to make things like below Ill use spaces.
Basically indenting = tabs
formatting = spaces.

Basically I like the 4 spaces hard tab while my programming buddy uses 2 space hard tab. So it makes it nice when we switch back and forth since he will be on 2 and I can be on 4 without any issues down the road.

Also ends up saving on character sizes too. Plus the flexibility.

Code:
[FONT="Courier New"]
$username = 'test';
$pass     = 'test';[/FONT]
 
please god, use spaces. I hate loading code that has tabs in it because the settings of whoever edited it are often different from mine, the tabs are usually mixed with spaces and end results is that it looks like jumbled crap. Not worth saving a few bytes of source file size.
 
please god, use spaces. I hate loading code that has tabs in it because the settings of whoever edited it are often different from mine, the tabs are usually mixed with spaces and end results is that it looks like jumbled crap. Not worth saving a few bytes of source file size.

While I agree somewhat that is the programmers fault for not following their own standards...

It makes editing my code so much easier when its tabs since I can select a block of code and indent it. While with spaces id have to hit each line and add the spaces to each line.

All my code is nicely formatted with tabs, and spaces for setting up blocks of code as white space.
 
Back
Top