Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Use spaces instead of tabs

Use spaces instead of tabs

Scheduled Pinned Locked Moved The Lounge
visual-studioquestioncsharpphpcss
37 Posts 20 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Marc Clifton

    In the Coder Interview with Chris Sells[^], he writes: #2. Use spaces instead of tabs. Rule #2 is just good sense. Really? I use tabs, I love tabs, I think spaces are ridiculous. Why are spaces "just good sense?" Makes no sense to me! Why do tabs make sense to me? Well, they are less keystrokes when I'm indenting a line of code. I can easily "Ctrl-TAB" a few times to get everything flush against the left margin when copying code for an article or a document. The cursor skips all the whitespace for each tab. It would be annoying as hell to use spaces! Oh, and the tab key is a heck of a lot quieter on the keyboard then the spacebar! [edit]I'm obviously asking an obsolete question. CP Insider: Tabs vs. Spaces[^] [/edit] Marc

    My Blog
    The Relationship Oriented Programming IDE
    Melody's Amazon Herb Site

    R Offline
    R Offline
    R Giskard Reventlov
    wrote on last edited by
    #2

    See my reply! I agree: tabs are de rigeur: spaces are simply ridiculous. [mod] just realised I'm talking about the post in the insider yesterday on the same subject!

    "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

    M 1 Reply Last reply
    0
    • M Marc Clifton

      In the Coder Interview with Chris Sells[^], he writes: #2. Use spaces instead of tabs. Rule #2 is just good sense. Really? I use tabs, I love tabs, I think spaces are ridiculous. Why are spaces "just good sense?" Makes no sense to me! Why do tabs make sense to me? Well, they are less keystrokes when I'm indenting a line of code. I can easily "Ctrl-TAB" a few times to get everything flush against the left margin when copying code for an article or a document. The cursor skips all the whitespace for each tab. It would be annoying as hell to use spaces! Oh, and the tab key is a heck of a lot quieter on the keyboard then the spacebar! [edit]I'm obviously asking an obsolete question. CP Insider: Tabs vs. Spaces[^] [/edit] Marc

      My Blog
      The Relationship Oriented Programming IDE
      Melody's Amazon Herb Site

      N Offline
      N Offline
      Nemanja Trifunovic
      wrote on last edited by
      #3

      The only thing I have to say about the matter is: pick one. The only standard I can't stand is having a source file where some lines start with spaces and other with tabs. Other than that, it simply doesn't matter.

      utf8-cpp

      1 Reply Last reply
      0
      • R R Giskard Reventlov

        See my reply! I agree: tabs are de rigeur: spaces are simply ridiculous. [mod] just realised I'm talking about the post in the insider yesterday on the same subject!

        "If you think it's expensive to hire a professional to do the job, wait until you hire an amateur." Red Adair. nils illegitimus carborundum me, me, me

        M Offline
        M Offline
        Marc Clifton
        wrote on last edited by
        #4

        mark merrens wrote:

        [mod] just realised I'm talking about the post in the insider yesterday on the same subject!

        Yeah, I just noticed that! Ah well, I'm being the times as usual! Marc

        My Blog
        The Relationship Oriented Programming IDE
        Melody's Amazon Herb Site

        1 Reply Last reply
        0
        • M Marc Clifton

          In the Coder Interview with Chris Sells[^], he writes: #2. Use spaces instead of tabs. Rule #2 is just good sense. Really? I use tabs, I love tabs, I think spaces are ridiculous. Why are spaces "just good sense?" Makes no sense to me! Why do tabs make sense to me? Well, they are less keystrokes when I'm indenting a line of code. I can easily "Ctrl-TAB" a few times to get everything flush against the left margin when copying code for an article or a document. The cursor skips all the whitespace for each tab. It would be annoying as hell to use spaces! Oh, and the tab key is a heck of a lot quieter on the keyboard then the spacebar! [edit]I'm obviously asking an obsolete question. CP Insider: Tabs vs. Spaces[^] [/edit] Marc

          My Blog
          The Relationship Oriented Programming IDE
          Melody's Amazon Herb Site

          C Offline
          C Offline
          cpkilekofp
          wrote on last edited by
          #5

          Tabs are great for offsetting text quickly. I usually set my environment, if I can, to tabs of four spaces and to fill out tabs with spaces on a save. Why don't I keep the tabs? Because once I insert the text where it belongs, I don't need the tabs, and the next guy to edit might have tabs set to eight columns, thus ruining my beautiful code layout.

          M P Z 3 Replies Last reply
          0
          • M Marc Clifton

            In the Coder Interview with Chris Sells[^], he writes: #2. Use spaces instead of tabs. Rule #2 is just good sense. Really? I use tabs, I love tabs, I think spaces are ridiculous. Why are spaces "just good sense?" Makes no sense to me! Why do tabs make sense to me? Well, they are less keystrokes when I'm indenting a line of code. I can easily "Ctrl-TAB" a few times to get everything flush against the left margin when copying code for an article or a document. The cursor skips all the whitespace for each tab. It would be annoying as hell to use spaces! Oh, and the tab key is a heck of a lot quieter on the keyboard then the spacebar! [edit]I'm obviously asking an obsolete question. CP Insider: Tabs vs. Spaces[^] [/edit] Marc

            My Blog
            The Relationship Oriented Programming IDE
            Melody's Amazon Herb Site

            L Offline
            L Offline
            loctrice
            wrote on last edited by
            #6

            I don't really mind as long as it's consistent. The only thing I can say for tabs is that it matches user prefs easier. If my editer says a tab is 4 and yours says it's 8 then we are both happy. Spaces don't do that as far as I know. Either way, it doesn't matter much to me. I think the argument is amusing though :D

            If it moves, compile it

            1 Reply Last reply
            0
            • M Marc Clifton

              In the Coder Interview with Chris Sells[^], he writes: #2. Use spaces instead of tabs. Rule #2 is just good sense. Really? I use tabs, I love tabs, I think spaces are ridiculous. Why are spaces "just good sense?" Makes no sense to me! Why do tabs make sense to me? Well, they are less keystrokes when I'm indenting a line of code. I can easily "Ctrl-TAB" a few times to get everything flush against the left margin when copying code for an article or a document. The cursor skips all the whitespace for each tab. It would be annoying as hell to use spaces! Oh, and the tab key is a heck of a lot quieter on the keyboard then the spacebar! [edit]I'm obviously asking an obsolete question. CP Insider: Tabs vs. Spaces[^] [/edit] Marc

              My Blog
              The Relationship Oriented Programming IDE
              Melody's Amazon Herb Site

              B Offline
              B Offline
              BobJanova
              wrote on last edited by
              #7

              I have never understood this one. Tabs allow different developers to set up their editors how they want, and having everyone being comfortable with the codebase is obviously a good thing. (Personally I like a really narrow tab stop to stop code vanishing off to the right, which I manage in space-land by coding in a proportional font.) It's also far harder to muck up indentation if you're using tabs (it's very easy to be modifying indentation and end up with 7 or 9 spaces not 8, but you really notice 2 or 3 tabs). Enforcing a particular spacing standard means that some people are constantly dealing with code that (to them) is too indented, or not indented enough. If the codebase used tabs, they could all work with it in the best possible way. Most modern IDEs do a lot of paddling for you to fake the useful aspects of tabs with spaces. So why not just use tabs in the first place?

              1 Reply Last reply
              0
              • M Marc Clifton

                In the Coder Interview with Chris Sells[^], he writes: #2. Use spaces instead of tabs. Rule #2 is just good sense. Really? I use tabs, I love tabs, I think spaces are ridiculous. Why are spaces "just good sense?" Makes no sense to me! Why do tabs make sense to me? Well, they are less keystrokes when I'm indenting a line of code. I can easily "Ctrl-TAB" a few times to get everything flush against the left margin when copying code for an article or a document. The cursor skips all the whitespace for each tab. It would be annoying as hell to use spaces! Oh, and the tab key is a heck of a lot quieter on the keyboard then the spacebar! [edit]I'm obviously asking an obsolete question. CP Insider: Tabs vs. Spaces[^] [/edit] Marc

                My Blog
                The Relationship Oriented Programming IDE
                Melody's Amazon Herb Site

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #8

                I used to think tabs were great, but that was before text editors got a clue. Now [Home] skips the whitespace and arrow keys navigate to sensible places. Tabs still aren't bad when used for indenting, but they (perhaps ironically) suck for aligning. For example in

                if (something\_longer\_than\_this &&
                    something\_else\_long)
                

                If tabs are used it risks becoming

                if (something_longer_than_this &&
                something_else_long)

                or

                    if (something\_longer\_than\_this &&
                            something\_else\_long)
                

                Depending on someones settings. When tabs and spaces are mixed, things tend to go wrong, possibly because it's hard to tell the difference between a tab and a bunch of spaces especially when they've become mixed arbitrarily. Through copy/paste and incremental editing, whitespaces slowly become tab/space mixes that only accidentally have the right size for whatever edited it last. If everything is a space but the editor treats whitespace properly instead of "just an other character" IMO its disadvantages mostly disappear, but the advantages remain. The same could afaik not be done for tabs.

                B L Z 3 Replies Last reply
                0
                • M Marc Clifton

                  In the Coder Interview with Chris Sells[^], he writes: #2. Use spaces instead of tabs. Rule #2 is just good sense. Really? I use tabs, I love tabs, I think spaces are ridiculous. Why are spaces "just good sense?" Makes no sense to me! Why do tabs make sense to me? Well, they are less keystrokes when I'm indenting a line of code. I can easily "Ctrl-TAB" a few times to get everything flush against the left margin when copying code for an article or a document. The cursor skips all the whitespace for each tab. It would be annoying as hell to use spaces! Oh, and the tab key is a heck of a lot quieter on the keyboard then the spacebar! [edit]I'm obviously asking an obsolete question. CP Insider: Tabs vs. Spaces[^] [/edit] Marc

                  My Blog
                  The Relationship Oriented Programming IDE
                  Melody's Amazon Herb Site

                  S Offline
                  S Offline
                  Steve Wellens
                  wrote on last edited by
                  #9

                  Here's some code with tabs. When you share code with tabs, it can be ugly.

                  public class MyClass
                  {
                  void MyFunction()
                  {
                  if (true)
                  {
                  for (int x = 0; x < 3; x++)
                  {
                  if (false)
                  continue;
                  }
                  }
                  }
                  }

                  Steve Wellens

                  M B L 3 Replies Last reply
                  0
                  • M Marc Clifton

                    In the Coder Interview with Chris Sells[^], he writes: #2. Use spaces instead of tabs. Rule #2 is just good sense. Really? I use tabs, I love tabs, I think spaces are ridiculous. Why are spaces "just good sense?" Makes no sense to me! Why do tabs make sense to me? Well, they are less keystrokes when I'm indenting a line of code. I can easily "Ctrl-TAB" a few times to get everything flush against the left margin when copying code for an article or a document. The cursor skips all the whitespace for each tab. It would be annoying as hell to use spaces! Oh, and the tab key is a heck of a lot quieter on the keyboard then the spacebar! [edit]I'm obviously asking an obsolete question. CP Insider: Tabs vs. Spaces[^] [/edit] Marc

                    My Blog
                    The Relationship Oriented Programming IDE
                    Melody's Amazon Herb Site

                    L Offline
                    L Offline
                    LloydA111
                    wrote on last edited by
                    #10

                    Spaces instead of tabs is damn frustrating and irritating!


                    See if you can crack this: b749f6c269a746243debc6488046e33f
                    So far, no one seems to have cracked this!

                    The unofficial awesome history of Code Project's Bob! "People demand freedom of speech to make up for the freedom of thought which they avoid."

                    L 1 Reply Last reply
                    0
                    • S Steve Wellens

                      Here's some code with tabs. When you share code with tabs, it can be ugly.

                      public class MyClass
                      {
                      void MyFunction()
                      {
                      if (true)
                      {
                      for (int x = 0; x < 3; x++)
                      {
                      if (false)
                      continue;
                      }
                      }
                      }
                      }

                      Steve Wellens

                      M Offline
                      M Offline
                      Marc Clifton
                      wrote on last edited by
                      #11

                      Steve Wellens wrote:

                      When you share code with tabs, it can be ugly.

                      But my tabs are set for 4 spaces, so the code looks nice! Marc

                      My Blog
                      The Relationship Oriented Programming IDE
                      Melody's Amazon Herb Site

                      1 Reply Last reply
                      0
                      • L Lost User

                        I used to think tabs were great, but that was before text editors got a clue. Now [Home] skips the whitespace and arrow keys navigate to sensible places. Tabs still aren't bad when used for indenting, but they (perhaps ironically) suck for aligning. For example in

                        if (something\_longer\_than\_this &&
                            something\_else\_long)
                        

                        If tabs are used it risks becoming

                        if (something_longer_than_this &&
                        something_else_long)

                        or

                            if (something\_longer\_than\_this &&
                                    something\_else\_long)
                        

                        Depending on someones settings. When tabs and spaces are mixed, things tend to go wrong, possibly because it's hard to tell the difference between a tab and a bunch of spaces especially when they've become mixed arbitrarily. Through copy/paste and incremental editing, whitespaces slowly become tab/space mixes that only accidentally have the right size for whatever edited it last. If everything is a space but the editor treats whitespace properly instead of "just an other character" IMO its disadvantages mostly disappear, but the advantages remain. The same could afaik not be done for tabs.

                        B Offline
                        B Offline
                        BobJanova
                        wrote on last edited by
                        #12

                        Spaces don't work for that anyway if you don't use a fixed pitch font. A line like that should start 'tab space space space space', anyway, for me – the real indentation level of the second part of the condition is the same as the start of the condition and the tabs (for code rolling up etc) should reflect that.

                        C R 2 Replies Last reply
                        0
                        • S Steve Wellens

                          Here's some code with tabs. When you share code with tabs, it can be ugly.

                          public class MyClass
                          {
                          void MyFunction()
                          {
                          if (true)
                          {
                          for (int x = 0; x < 3; x++)
                          {
                          if (false)
                          continue;
                          }
                          }
                          }
                          }

                          Steve Wellens

                          B Offline
                          B Offline
                          BobJanova
                          wrote on last edited by
                          #13

                          In a browser? Sure, because you can't set the tab stop. But how often do you do that? Code with 4 spaces per indent level is just as ugly as this to someone who prefers 1 or 2.

                          L 1 Reply Last reply
                          0
                          • C cpkilekofp

                            Tabs are great for offsetting text quickly. I usually set my environment, if I can, to tabs of four spaces and to fill out tabs with spaces on a save. Why don't I keep the tabs? Because once I insert the text where it belongs, I don't need the tabs, and the next guy to edit might have tabs set to eight columns, thus ruining my beautiful code layout.

                            M Offline
                            M Offline
                            Marc Clifton
                            wrote on last edited by
                            #14

                            cpkilekofp wrote:

                            I don't need the tabs, and the next guy to edit might have tabs set to eight columns, thus ruining my beautiful code layout.

                            Yes, but when he edits your code and growls at your 4-space tabs converted to spaces because they don't align with 8-space tabs, and he just ignores that, you'll get back uglified code. :) I think. :~ Marc

                            My Blog
                            The Relationship Oriented Programming IDE
                            Melody's Amazon Herb Site

                            C 1 Reply Last reply
                            0
                            • B BobJanova

                              Spaces don't work for that anyway if you don't use a fixed pitch font. A line like that should start 'tab space space space space', anyway, for me – the real indentation level of the second part of the condition is the same as the start of the condition and the tabs (for code rolling up etc) should reflect that.

                              C Offline
                              C Offline
                              cpkilekofp
                              wrote on last edited by
                              #15

                              BobJanova wrote:

                              Spaces don't work for that anyway if you don't use a fixed pitch font.

                              I never code except in a fixed pitch font. I've never found code readability to be enhanced by using a proportional font, and often found it very distracting, so after a couple of experiments I stuck to Courier and continue to do so.

                              1 Reply Last reply
                              0
                              • L Lost User

                                I used to think tabs were great, but that was before text editors got a clue. Now [Home] skips the whitespace and arrow keys navigate to sensible places. Tabs still aren't bad when used for indenting, but they (perhaps ironically) suck for aligning. For example in

                                if (something\_longer\_than\_this &&
                                    something\_else\_long)
                                

                                If tabs are used it risks becoming

                                if (something_longer_than_this &&
                                something_else_long)

                                or

                                    if (something\_longer\_than\_this &&
                                            something\_else\_long)
                                

                                Depending on someones settings. When tabs and spaces are mixed, things tend to go wrong, possibly because it's hard to tell the difference between a tab and a bunch of spaces especially when they've become mixed arbitrarily. Through copy/paste and incremental editing, whitespaces slowly become tab/space mixes that only accidentally have the right size for whatever edited it last. If everything is a space but the editor treats whitespace properly instead of "just an other character" IMO its disadvantages mostly disappear, but the advantages remain. The same could afaik not be done for tabs.

                                L Offline
                                L Offline
                                loctrice
                                wrote on last edited by
                                #16

                                Some people use vim, gedit, emacs, nano, pico, etc. Your definition of "treating spaces properly" is a point of view. I know a developer that uses notepad the same way I use gedit. I don't think he would agree with you :P

                                If it moves, compile it

                                1 Reply Last reply
                                0
                                • B BobJanova

                                  In a browser? Sure, because you can't set the tab stop. But how often do you do that? Code with 4 spaces per indent level is just as ugly as this to someone who prefers 1 or 2.

                                  L Offline
                                  L Offline
                                  loctrice
                                  wrote on last edited by
                                  #17

                                  I usually set my tabs to 4 spaces. I do a lot of work in vim in a standard sized gui terminal (because I tend to have several of them open). It looks just fine, even when I open it in Gedit. The benefit of tabs is that if you think 4 is ugly, your editor will use whatever tab setting you have and you'd never know.

                                  If it moves, compile it

                                  B 1 Reply Last reply
                                  0
                                  • M Marc Clifton

                                    cpkilekofp wrote:

                                    I don't need the tabs, and the next guy to edit might have tabs set to eight columns, thus ruining my beautiful code layout.

                                    Yes, but when he edits your code and growls at your 4-space tabs converted to spaces because they don't align with 8-space tabs, and he just ignores that, you'll get back uglified code. :) I think. :~ Marc

                                    My Blog
                                    The Relationship Oriented Programming IDE
                                    Melody's Amazon Herb Site

                                    C Offline
                                    C Offline
                                    cpkilekofp
                                    wrote on last edited by
                                    #18

                                    LOL true. This gave rise to some "standards" battles in a couple of places I worked: 4-space tabs vs. eight-space vs. no-tabs-whatsoever in one case. Best solution? A pretty-printer plug-in that formats the code the way you want to see it.

                                    1 Reply Last reply
                                    0
                                    • S Steve Wellens

                                      Here's some code with tabs. When you share code with tabs, it can be ugly.

                                      public class MyClass
                                      {
                                      void MyFunction()
                                      {
                                      if (true)
                                      {
                                      for (int x = 0; x < 3; x++)
                                      {
                                      if (false)
                                      continue;
                                      }
                                      }
                                      }
                                      }

                                      Steve Wellens

                                      L Offline
                                      L Offline
                                      loctrice
                                      wrote on last edited by
                                      #19

                                      This does not look off to me. I'm used to seeing 4 as well as 8 depending on if I'm in a terminal or gui editor. Neither bother me. I'm also used to seeing code with no indentation, as well as spiratic indentation :D

                                      If it moves, compile it

                                      1 Reply Last reply
                                      0
                                      • L LloydA111

                                        Spaces instead of tabs is damn frustrating and irritating!


                                        See if you can crack this: b749f6c269a746243debc6488046e33f
                                        So far, no one seems to have cracked this!

                                        The unofficial awesome history of Code Project's Bob! "People demand freedom of speech to make up for the freedom of thought which they avoid."

                                        L Offline
                                        L Offline
                                        loctrice
                                        wrote on last edited by
                                        #20

                                        Depending on your editor you can always refactor them. If you open a source file in something like vim you can use a quick search and replace. You can always put it back when you are done so when they get the file back they are still happy. You can use sed before and after you work in it. You can replace before you open, and then put it back to the authors preference after you are done.

                                        If it moves, compile it

                                        1 Reply Last reply
                                        0
                                        • M Marc Clifton

                                          In the Coder Interview with Chris Sells[^], he writes: #2. Use spaces instead of tabs. Rule #2 is just good sense. Really? I use tabs, I love tabs, I think spaces are ridiculous. Why are spaces "just good sense?" Makes no sense to me! Why do tabs make sense to me? Well, they are less keystrokes when I'm indenting a line of code. I can easily "Ctrl-TAB" a few times to get everything flush against the left margin when copying code for an article or a document. The cursor skips all the whitespace for each tab. It would be annoying as hell to use spaces! Oh, and the tab key is a heck of a lot quieter on the keyboard then the spacebar! [edit]I'm obviously asking an obsolete question. CP Insider: Tabs vs. Spaces[^] [/edit] Marc

                                          My Blog
                                          The Relationship Oriented Programming IDE
                                          Melody's Amazon Herb Site

                                          C Offline
                                          C Offline
                                          cpkilekofp
                                          wrote on last edited by
                                          #21

                                          The classic solution to the indentation issue (and where braces go in C-like languages, etc.) is the pretty-printer. This is a language-sensitive tool which you may have to build yourself, but many languages have pretty-printers available for them with settings appropriate to that language. For languages that aren't whitespace-sensitive, this allows you to eliminate any whitespace except where required for string separation in the stored file while the pretty-printer formats the stored file into whatever viewing preference you have. This also works with any text editor: pretty-print the source file into a file you will edit, edit that file, then pretty-print it back into a compressed format. Hmmm, sounds like an article for someone there. As for Rule #2, to my mind, no assertion without an explanation or justification just makes good sense. One man's "common sense" is someone else's dearly acquired skill.

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups