Tabs or Spaces?

Discussion in 'Web Design and Development' started by DipDog3, Jan 9, 2009.

  1. DipDog3 macrumors 65816


    Sep 20, 2002
    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.
  2. Cabbit macrumors 68020


    Jan 30, 2006
    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.

            // Comment about what the block of code does, a few more comments too if needed //
    	do something
    		do something else a few times
  3. angelwatt Moderator emeritus


    Aug 16, 2005
    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.
  4. bootedbear macrumors 6502


    Sep 13, 2004
    Austin, TX
  5. thewright1 macrumors regular


    Apr 3, 2008
    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.
  6. memco macrumors 6502

    May 1, 2008
    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.
  7. jeremy.king macrumors 603


    Jul 23, 2002
    Fuquay Varina, NC
    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

Share This Page