PDA

View Full Version : Tabs or Spaces?




DipDog3
Jan 9, 2009, 03:12 PM
Which is best to use when indenting code... Tabs or Spaces?

And how many "spaces" should the indent be? 2, 4, 8?

As applies to PHP, HTML, and CSS code.



babyjenniferLB
Jan 9, 2009, 03:29 PM
tabs a bit like this.

note: it does not effect the working of your program if your code is in one continuous line or neatly laid out. This is only for people including yourself to read your code.



function
{
// Comment about what the block of code does, a few more comments too if needed //
do something

loop
{
do something else a few times
}
}

angelwatt
Jan 9, 2009, 03:36 PM
Well, first, it's totally coder dependent (no right or wrong). Me, I use 2 spaces per indent because I hate code getting pushed too far to the right, and I find it easier to hit the space bar than the tab key so my typing is quicker using spaces. Though, my editor (BBEdit) allows me to use the tab key and have it interpreted as two spaces so I can still use that key if I like.

You can make the argument though that tabs are better because they result in slightly smaller file sizes since one tab equals one space in terms of file size. So, if you use tabs that are worth 4 spaces, then you can have rather large file size differences between the two methods. The size difference generally only matters with large files. On issue with tabs though, is that text editor treat the tab size differently. Like I mentioned earlier BBEdit lets me choose tab sizes. Spaces on the other hand will look the same no matter what editor you use.

bootedbear
Jan 9, 2009, 07:29 PM
Well, first, it's totally coder dependent (no right or wrong). Me, I use 2 spaces per indent because I hate code getting pushed too far to the right, and I find it easier to hit the space bar than the tab key so my typing is quicker using spaces. Though, my editor (BBEdit) allows me to use the tab key and have it interpreted as two spaces so I can still use that key if I like.
This.

thewright1
Jan 10, 2009, 01:07 PM
Im an ActionScripter, so tabs definitely work the best for that. I also use tabs in PHP. The only time I use spaces is in HTML but I try to use tabs whenever possible. It just seems faster a little more accurate to me.

memco
Jan 11, 2009, 02:44 PM
I'm a fan of tabs because they're easier to keep track of; I usually only have 3 or 4 on one line at most. If I use spaces, that would be up to 32 characters I might have to traverse.

jeremy.king
Jan 14, 2009, 05:42 PM
I usually don't like to have to mess with various tab display preferences with whatever tool I'm using.

Spaces, 2 to be exact