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. Keep tabs as tabs or tabs as spaces

Keep tabs as tabs or tabs as spaces

Scheduled Pinned Locked Moved The Lounge
question
48 Posts 35 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.
  • R Rob Philpott

    You know what I mean - you can have it so that a tab is a tab, and backspace removes it - or you can have it as usually 4 spaces so one tab takes four backspace hits to remove it. I like the first way and despise the second (it offends my need for symmetry), but seem to be alone in this in my current place of work. Or worse yet - "does it matter?" Please reassure me I'm in the right really....

    Regards, Rob Philpott.

    T Offline
    T Offline
    TheGreatAndPowerfulOz
    wrote on last edited by
    #14

    I would agree with you if I could have tabs as tabs that indent and tabs as spaces on the "interior".

    "If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams

    1 Reply Last reply
    0
    • R Rob Philpott

      You know what I mean - you can have it so that a tab is a tab, and backspace removes it - or you can have it as usually 4 spaces so one tab takes four backspace hits to remove it. I like the first way and despise the second (it offends my need for symmetry), but seem to be alone in this in my current place of work. Or worse yet - "does it matter?" Please reassure me I'm in the right really....

      Regards, Rob Philpott.

      B Offline
      B Offline
      BRShroyer
      wrote on last edited by
      #15

      I use a ball-peen hammer to indent my code. I carry it everwhere I go. Ever since then, I have had fewer bugs, or at least complaints from the users. Ironically I was looking at this[^] earlier today. To save you the trip, it's about using two spaces or one after a period.

      Brad Deja Moo - When you feel like you've heard the same bull before.

      1 Reply Last reply
      0
      • R Rob Philpott

        You know what I mean - you can have it so that a tab is a tab, and backspace removes it - or you can have it as usually 4 spaces so one tab takes four backspace hits to remove it. I like the first way and despise the second (it offends my need for symmetry), but seem to be alone in this in my current place of work. Or worse yet - "does it matter?" Please reassure me I'm in the right really....

        Regards, Rob Philpott.

        G Offline
        G Offline
        Gary Wheeler
        wrote on last edited by
        #16

        The Minion and I agreed to a compromise. He prefers spaces, and a tab width of 3. I prefer tabs, and a width of 4. We compromised on spaces and a tab width of 4. Of course, if he doesn't stop using Hungarian notation (in C# no less), they'll find his body floating face down in a culvert somewhere...

        Software Zen: delete this;

        M 1 Reply Last reply
        0
        • R Rob Philpott

          You know what I mean - you can have it so that a tab is a tab, and backspace removes it - or you can have it as usually 4 spaces so one tab takes four backspace hits to remove it. I like the first way and despise the second (it offends my need for symmetry), but seem to be alone in this in my current place of work. Or worse yet - "does it matter?" Please reassure me I'm in the right really....

          Regards, Rob Philpott.

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

          If I prefer a layout with, say, 4 spaces of indent and a co-worker prefers just 2, using spaces means one of us has to suffer. Using Tabs means we can adjust our tabs and see the layout we like (depending on the editor, for sure). VS2010 Pro Power Tools has an option to tell you when you have mixed spaces and tabs, and fix it (into tabs or spaces) for you. So set it up how you want to in VS and let the tools do their job. Of course, if you're not using VS2010 you may have to look at other options - but I believe that the tools we use should provide what we want, and not require us to modify our behavior to suit them.

          ___________________________________________ .\\axxx (That's an 'M')

          1 Reply Last reply
          0
          • P Peter Mulholland

            I used to think like you, but then I had to deal with a file comparison tool that used 8 spaces for tabs and couldn't be changed. Replace tabs with spaces. ALWAYS! 4 backspaces doesn't take that long. Modern IDEs should reduce that to 1 keystroke anyway. I've found I have much less problems across editors and merge utilites and diff programs when I use spaces.

            Pete

            T Offline
            T Offline
            tom1443
            wrote on last edited by
            #18

            I'm in the minority but I agree with Pete - spaces always.

            R 1 Reply Last reply
            0
            • R Rob Philpott

              You know what I mean - you can have it so that a tab is a tab, and backspace removes it - or you can have it as usually 4 spaces so one tab takes four backspace hits to remove it. I like the first way and despise the second (it offends my need for symmetry), but seem to be alone in this in my current place of work. Or worse yet - "does it matter?" Please reassure me I'm in the right really....

              Regards, Rob Philpott.

              B Offline
              B Offline
              Ben Barreth
              wrote on last edited by
              #19

              With my favorite code editors, the convention is: If I select multiple lines and hit tab, it indents it all. If I select multiple lines and hit space, it replaces it all with a single space. 'Nuff said. IMHO this point alone makes tabs the natural choice to mass format lines of code. Sure some editors allow you to get around this by having options to convert the tabs into spaces (so you can still tab multiple lines, the editor just immediately converts them to whitespace). But not all editors have this, which means you may end up changing the format of your code depending on which editor you have open (e.g. VS2010 with the tab-to-space conversion enabled versus SQL studio which doesn't have the option AFAIK).

              P 1 Reply Last reply
              0
              • G Gary Wheeler

                The Minion and I agreed to a compromise. He prefers spaces, and a tab width of 3. I prefer tabs, and a width of 4. We compromised on spaces and a tab width of 4. Of course, if he doesn't stop using Hungarian notation (in C# no less), they'll find his body floating face down in a culvert somewhere...

                Software Zen: delete this;

                M Offline
                M Offline
                Matthew Wilcoxson
                wrote on last edited by
                #20

                Wouldn't it been fairer to use tabs, then you could set the tab to be 3 or 4 or whatever number of spaces wide you like!

                G 1 Reply Last reply
                0
                • M Matthew Wilcoxson

                  Wouldn't it been fairer to use tabs, then you could set the tab to be 3 or 4 or whatever number of spaces wide you like!

                  G Offline
                  G Offline
                  Gary Wheeler
                  wrote on last edited by
                  #21

                  No, because Visual Studio (at least as recently as VS2008), still does not handle tabs correctly, especially when block indenting a selection.

                  Software Zen: delete this;

                  J G 2 Replies Last reply
                  0
                  • R Rob Philpott

                    You know what I mean - you can have it so that a tab is a tab, and backspace removes it - or you can have it as usually 4 spaces so one tab takes four backspace hits to remove it. I like the first way and despise the second (it offends my need for symmetry), but seem to be alone in this in my current place of work. Or worse yet - "does it matter?" Please reassure me I'm in the right really....

                    Regards, Rob Philpott.

                    R Offline
                    R Offline
                    R Erasmus
                    wrote on last edited by
                    #22

                    At our company and part of our coding standard, no tabs aloud and there is a good reason for it too. Opening files that uses tabs in different editors can create a mess of things. We use 2 space intentation only which limit the backspace to only 2 presses. And then there is always which eliminates the 2 backspaces. Use tab as long as your editor automatically converts tabs to spaces I'll recommend.

                    "Program testing can be used to show the presence of bugs, but never to show their absence." << please vote!! >>

                    1 Reply Last reply
                    0
                    • R Rob Philpott

                      You know what I mean - you can have it so that a tab is a tab, and backspace removes it - or you can have it as usually 4 spaces so one tab takes four backspace hits to remove it. I like the first way and despise the second (it offends my need for symmetry), but seem to be alone in this in my current place of work. Or worse yet - "does it matter?" Please reassure me I'm in the right really....

                      Regards, Rob Philpott.

                      C Offline
                      C Offline
                      code_junkie
                      wrote on last edited by
                      #23

                      Tabs for indenting, spaces everywhere else! :thumbsup:

                      1 Reply Last reply
                      0
                      • R Rob Philpott

                        You know what I mean - you can have it so that a tab is a tab, and backspace removes it - or you can have it as usually 4 spaces so one tab takes four backspace hits to remove it. I like the first way and despise the second (it offends my need for symmetry), but seem to be alone in this in my current place of work. Or worse yet - "does it matter?" Please reassure me I'm in the right really....

                        Regards, Rob Philpott.

                        S Offline
                        S Offline
                        S Houghtelin
                        wrote on last edited by
                        #24

                        We recently went through a rewrite of our software standards and the company now mandates spaces over tabs. The reason for this is that every coder has their preferences, tabs, spaces, tabs whatever. We use several different IDEs and compilers with their respective editors for each microprocessor platform we use but we have a common algorithm that we use for our products. What looks aesthetically nice in one editor looks like crap in another. This can make it difficult when the spacing is different or a particular editor does not have the ignore whitespace function when comparing code. Then there’s the version control software and viewers, and so on. Most of the editors allow you to choose between spaces or tabs when using the tab key but will not convert the tabs to spaces when viewing code. So for me it’s not a matter of preference, I have to use spaces, but I have to admit, it is nice when the code indentation matches the rest of the code regardless of what I am using to view the code. And makes the compares easier to go though during V&V :zzz: .

                        It was broke, so I fixed it.

                        1 Reply Last reply
                        0
                        • E Ennis Ray Lynch Jr

                          It is the efficient vs. the lazy in this argument. Most people are too lazy to change the flow. VS defaults to spaces so why change it. Watch the people who are in favor of coding with spaces actually code. Watch how slow they (usually) work. I am a tab man. All of my code is used only on Windows. I don't have to deal with using Unix and Windows for the same code base and I can type. Yes it matters. There is nothing worse than having to break away from the keyboard to use the mouse.

                          Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. I also do Android Programming as I find it a refreshing break from the MS. "And they, since they Were not the one dead, turned to their affairs" -- Robert Frost

                          P Offline
                          P Offline
                          Peter Mulholland
                          wrote on last edited by
                          #25

                          Ennis Ray Lynch, Jr. wrote:

                          VS defaults to spaces so why change it.

                          Really? I've always been under the impression that the default in VS is tabs, at least I've always had to go into the options to check the 'replace tabd with spaces' option.

                          Ennis Ray Lynch, Jr. wrote:

                          It is the efficient vs. the lazy in this argument. Most people are too lazy to change the flow

                          I think my previous comment debunks this idea.

                          Ennis Ray Lynch, Jr. wrote:

                          Watch the people who are in favor of coding with spaces actually code. Watch how slow they (usually) work

                          how do you think replacing tabs with spaces actually slows down coding? I just don't get this one.

                          Ennis Ray Lynch, Jr. wrote:

                          Yes it matters. There is nothing worse than having to break away from the keyboard to use the mouse.

                          Again, why would using spaces require us to resort to the mouse more often? The Ctrl key is pretty damn handy for navigating through code.

                          Pete

                          1 Reply Last reply
                          0
                          • B Ben Barreth

                            With my favorite code editors, the convention is: If I select multiple lines and hit tab, it indents it all. If I select multiple lines and hit space, it replaces it all with a single space. 'Nuff said. IMHO this point alone makes tabs the natural choice to mass format lines of code. Sure some editors allow you to get around this by having options to convert the tabs into spaces (so you can still tab multiple lines, the editor just immediately converts them to whitespace). But not all editors have this, which means you may end up changing the format of your code depending on which editor you have open (e.g. VS2010 with the tab-to-space conversion enabled versus SQL studio which doesn't have the option AFAIK).

                            P Offline
                            P Offline
                            Peter Mulholland
                            wrote on last edited by
                            #26

                            Ben Barreth wrote:

                            If I select multiple lines and hit tab, it indents it all.

                            And with 'replace tabs with spaces' this will also work and replace all tabs with spaces, I use it regulary to 'correct' tabs to spaces in editors where I don't trust the 'nicify code' function.

                            Pete

                            1 Reply Last reply
                            0
                            • R Rob Philpott

                              You know what I mean - you can have it so that a tab is a tab, and backspace removes it - or you can have it as usually 4 spaces so one tab takes four backspace hits to remove it. I like the first way and despise the second (it offends my need for symmetry), but seem to be alone in this in my current place of work. Or worse yet - "does it matter?" Please reassure me I'm in the right really....

                              Regards, Rob Philpott.

                              A Offline
                              A Offline
                              Andre vd Wal
                              wrote on last edited by
                              #27

                              As a rule at our company we convert all tabs to spaces. This is to stay consistent throughout the code base and it also helps when it comes to merging branches in your source control system.

                              1 Reply Last reply
                              0
                              • R Rob Philpott

                                You know what I mean - you can have it so that a tab is a tab, and backspace removes it - or you can have it as usually 4 spaces so one tab takes four backspace hits to remove it. I like the first way and despise the second (it offends my need for symmetry), but seem to be alone in this in my current place of work. Or worse yet - "does it matter?" Please reassure me I'm in the right really....

                                Regards, Rob Philpott.

                                P Offline
                                P Offline
                                P0110X
                                wrote on last edited by
                                #28

                                I prefer tabs and I use to tab the document, so the source code control tool "ignores" the spacing pain

                                _class MySignature _{ __public override void toString() __{ ____return "hi ;)"; __} _}

                                1 Reply Last reply
                                0
                                • R Rob Philpott

                                  You know what I mean - you can have it so that a tab is a tab, and backspace removes it - or you can have it as usually 4 spaces so one tab takes four backspace hits to remove it. I like the first way and despise the second (it offends my need for symmetry), but seem to be alone in this in my current place of work. Or worse yet - "does it matter?" Please reassure me I'm in the right really....

                                  Regards, Rob Philpott.

                                  S Offline
                                  S Offline
                                  Stefan_Lang
                                  wrote on last edited by
                                  #29

                                  Rob Philpott wrote:

                                  Or worse yet - "does it matter?"

                                  If you want a hard answer, the answer is that most probably it does matter. Or, more to the point: if you know for sure that every tool you use to view, edit or in other way work with your source code files uses the same tab width, and every other developer working on the same files, and any other person who for some reason works with your files, only will use tools with that same tab width, then you're safe to use and store only tabs. Unfortunately, in 99% of all cases the above conditions are not met, and so you're 'safer' to store tabs as spaces instead. Having to backspace for formatting purposes - repeatedly or not - is something you shouldn't need to do at all - either you have specific functions to increase and decrease text indention, or your editor is smart enough to interpret a backspace at the start of a the text in a line as a command to decrease the indention (I've worked with such an editor once, but unfortunately can't remember it's name). Here are some examples on how stuff can get messed up by storing tabs instead of spaces: 1. Code comments appear unaligned because of different tab settings 2. Various developers see different indentions on different lines, because the tools they use insert formatting in different ways, including, possibly, spaces for indentions 3. Viewing changes becomes confusing because tabs and spaces might be considered different by the diff tool, even though the code itself is unchanged. Also alignment issues may arise from different tab settings for the viewer 4. Edit functions that cut/copy vertically blocks of text (only rectangular areas rather than whole lines) might not work properly when using tabs (ok, not many editors support that, and there is a very limited use for that functionality, but still...) Fortunately, most tools like editors and viewers can be set to use a distinct tab width, so if you feel more comfortable storing tabs, then just make sure that everyone does this and configures all their tools to use the right tab width. Then you're good to go. :) Unfortunately there's always someone who stores tabs as spaces ... ;P Personally, I do always store spaces, because this is the only way to make sure that everyone will see the indentations exactly as I made them. :cool:

                                  G 1 Reply Last reply
                                  0
                                  • T tom1443

                                    I'm in the minority but I agree with Pete - spaces always.

                                    R Offline
                                    R Offline
                                    Roland van der Plas
                                    wrote on last edited by
                                    #30

                                    I also agree. Referring to rule #9 of Elements of C# Style: Do not use "hard" tabs. I guess it's a rule for other languages as well..

                                    1 Reply Last reply
                                    0
                                    • S Stefan_Lang

                                      Rob Philpott wrote:

                                      Or worse yet - "does it matter?"

                                      If you want a hard answer, the answer is that most probably it does matter. Or, more to the point: if you know for sure that every tool you use to view, edit or in other way work with your source code files uses the same tab width, and every other developer working on the same files, and any other person who for some reason works with your files, only will use tools with that same tab width, then you're safe to use and store only tabs. Unfortunately, in 99% of all cases the above conditions are not met, and so you're 'safer' to store tabs as spaces instead. Having to backspace for formatting purposes - repeatedly or not - is something you shouldn't need to do at all - either you have specific functions to increase and decrease text indention, or your editor is smart enough to interpret a backspace at the start of a the text in a line as a command to decrease the indention (I've worked with such an editor once, but unfortunately can't remember it's name). Here are some examples on how stuff can get messed up by storing tabs instead of spaces: 1. Code comments appear unaligned because of different tab settings 2. Various developers see different indentions on different lines, because the tools they use insert formatting in different ways, including, possibly, spaces for indentions 3. Viewing changes becomes confusing because tabs and spaces might be considered different by the diff tool, even though the code itself is unchanged. Also alignment issues may arise from different tab settings for the viewer 4. Edit functions that cut/copy vertically blocks of text (only rectangular areas rather than whole lines) might not work properly when using tabs (ok, not many editors support that, and there is a very limited use for that functionality, but still...) Fortunately, most tools like editors and viewers can be set to use a distinct tab width, so if you feel more comfortable storing tabs, then just make sure that everyone does this and configures all their tools to use the right tab width. Then you're good to go. :) Unfortunately there's always someone who stores tabs as spaces ... ;P Personally, I do always store spaces, because this is the only way to make sure that everyone will see the indentations exactly as I made them. :cool:

                                      G Offline
                                      G Offline
                                      GenJerDan
                                      wrote on last edited by
                                      #31

                                      Yep, tabs are all well and good*, but too varied in size. I often open up a source in Notepad to check something and tabs send the text waaay out there to the right at times. *Any R. Stevie Moore fans here? :-D

                                      S 1 Reply Last reply
                                      0
                                      • G GenJerDan

                                        Yep, tabs are all well and good*, but too varied in size. I often open up a source in Notepad to check something and tabs send the text waaay out there to the right at times. *Any R. Stevie Moore fans here? :-D

                                        S Offline
                                        S Offline
                                        Stefan_Lang
                                        wrote on last edited by
                                        #32

                                        This is exactly what I have been thinking of. Just didn't bother to mention it, because it reminds me of at least three occasions I've seen a tool like Notepad++ being suggested as a 'must-have' replacement for this hopelessly outdated piece of nostalgic-ware. ;)

                                        1 Reply Last reply
                                        0
                                        • G Gary Wheeler

                                          No, because Visual Studio (at least as recently as VS2008), still does not handle tabs correctly, especially when block indenting a selection.

                                          Software Zen: delete this;

                                          J Offline
                                          J Offline
                                          jsc42
                                          wrote on last edited by
                                          #33

                                          Visual Studio? Use Notepad (for Windows), vi (for Unix / Linux), ISPF or TSO EDIT (for MVS), or EDIT or EDLIN or COPY CON: for MS-DOS. I always used to use 3 spaces with punched card and paper tape. I now use Tabs at the start of lines, after the command keyword and before '='; and single space everywhere else. It maximises visual layout whilst minimising storage / network bandwidth.

                                          G 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