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.
  • 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
      • L loctrice

        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 Offline
        B Offline
        BobJanova
        wrote on last edited by
        #22

        Yes, precisely (to your second paragraph).

        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
          Chris Meech
          wrote on last edited by
          #23

          I don't use either. In fact I don't even bother with new lines. My source files consist of one great big long line with no new line at the end of it all. You wouldn't believe how it easy it has become to fix or maintain things. Whenever a question comes up, I just tell one of the junior guys, go and fix it on line 1 in the source file. :)

          Chris Meech I am Canadian. [heard in a local bar] In theory there is no difference between theory and practice. In practice there is. [Yogi Berra] posting about Crystal Reports here is like discussing gay marriage on a catholic church’s website.[Nishant Sivakumar]

          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

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

            I don't mind tabs for indenting code, but tabs on the "interior" of a line of code wreak havoc. I wish code editors would allow for indenting with tabs with the tab key and insert spaces with the tab key on the "interior" of lines. For that reason I always stick with "insert spaces with the tab key"

            If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
            You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun

            F 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

              S Offline
              S Offline
              SkysTheLimit
              wrote on last edited by
              #25

              Where I work, the code has to go through certification and so a lot of people are looking at the source code using different editors and tools. We also automatically extract things like special comments out of the source code and using spaces makes it easier to view the result in any text editor. We have made it part of our coding standards not to have any tabs in the source code because they just don't come out consistently in all editors. Fortunately, VS has a convenient option to convert all tabs to spaces automatically, so we can still use the tab key for indenting :)

              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

                D Offline
                D Offline
                dazfuller
                wrote on last edited by
                #26

                I use spaces, tools like Visual studio will automatically use spaces if you press the tab key (if you configure it) so TAB and SHIFT-TAB work fine. Plus if you say "indent by 4 spaces" then it looks the same in everyone's editor whereas tabs can look different and send the formatting crazy. That's my preference anyway and its the preference we enforce on the project I'm working on in the style guidelines. Studio 2010 even has a nice plugin which will ask to "untabify" a document if you open one up and it detects tabs instead of spaces (actually it will do the reverse as well, if that's your preference)

                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.

                  P Offline
                  P Offline
                  Paul Sanders the other one
                  wrote on last edited by
                  #27

                  cpkilekofp wrote:

                  and the next guy to edit might have tabs set to eight columns, thus ruining my beautiful code layout

                  Exactly. Things can degenerate into a complete mess.

                  Paul Sanders http://www.alpinesoft.co.uk

                  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

                    F Offline
                    F Offline
                    Fabio Franco
                    wrote on last edited by
                    #28

                    Marc Clifton wrote:

                    Rule #2 is just good sense.

                    That's one of the things I replied on his article that I didn't agree with. It's a biased assumption. I myself have always used spaces until recently. I've been converted to the tabs religion and I am loving it.

                    "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson "Our heads are round so our thoughts can change direction." ― Francis Picabia

                    1 Reply Last reply
                    0
                    • T TheGreatAndPowerfulOz

                      I don't mind tabs for indenting code, but tabs on the "interior" of a line of code wreak havoc. I wish code editors would allow for indenting with tabs with the tab key and insert spaces with the tab key on the "interior" of lines. For that reason I always stick with "insert spaces with the tab key"

                      If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
                      You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun

                      F Offline
                      F Offline
                      Fabio Franco
                      wrote on last edited by
                      #29

                      ahmed zahmed wrote:

                      I don't mind tabs for indenting code, but tabs on the "interior" of a line of code wreak havoc.

                      Agreed. But you can still insert spaces with the space bars (after the tab indentation) when you're trying to align multi-line statements.

                      "To alcohol! The cause of, and solution to, all of life's problems" - Homer Simpson "Our heads are round so our thoughts can change direction." ― Francis Picabia

                      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.

                        R Offline
                        R Offline
                        Ralph Little
                        wrote on last edited by
                        #30

                        If you use Eclipse, the editor has a nice mixture mode that does this all for you. Tabs for indent, then spaces for alignment. Gives you the best of both worlds. Users can set Tab to whatever they prefer, and the code still looks right.

                        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.

                          Z Offline
                          Z Offline
                          Zan Lynx
                          wrote on last edited by
                          #31

                          Use a code style that doesn't depend on tab size for alignment. Instead of lining up your second line of function parameters with the first line, put all the parameters on separate lines and indent each line. Etc. Then it doesn't break your layout when the tab size changes. Plus, it doesn't make your code lean way over to the right side when you use an especially long function name. And, it makes it possible to use a regular font instead of monospace. Weird, I know.

                          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.

                            Z Offline
                            Z Offline
                            Zan Lynx
                            wrote on last edited by
                            #32

                            Which is why this is better:

                            if (
                            something_longer_than_this &&
                            something_else_long
                            )

                            L 1 Reply Last reply
                            0
                            • Z Zan Lynx

                              Which is why this is better:

                              if (
                              something_longer_than_this &&
                              something_else_long
                              )

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

                              I suppose that'll work, but that's not in any style guide I've seen. How common is it?

                              Z 1 Reply Last reply
                              0
                              • L Lost User

                                I suppose that'll work, but that's not in any style guide I've seen. How common is it?

                                Z Offline
                                Z Offline
                                Zan Lynx
                                wrote on last edited by
                                #34

                                Not very common, admittedly. I don't understand why. I suppose some people don't like the waste of vertical space.

                                H 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

                                  D Offline
                                  D Offline
                                  dannette
                                  wrote on last edited by
                                  #35

                                  When I code for the web, sometimes with tabs, when you 'view source' it just isn't pretty - especially if someone else coded it. It might look perfectly fine in my editor but put it on the web and it's all over the place. That's why I like to use spaces.

                                  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

                                    T Offline
                                    T Offline
                                    TNCaver
                                    wrote on last edited by
                                    #36

                                    I absolutely agree. Tabs line up for everyone the way they like it, and however their VS is set up - with 3 spaces, 4 spaces, n spaces, whatever. Once we've debated this one to death, maybe next we can settle once and for all where open and close braces should go and how to properly indent them. :laugh:

                                    public void TheRightWay() {
                                    // yer awesum codez here
                                    }

                                    public void TheWrongWay()
                                    {
                                    // yer bad wtf codez here
                                    }

                                    If you think 'goto' is evil, try writing an Assembly program without JMP.

                                    1 Reply Last reply
                                    0
                                    • Z Zan Lynx

                                      Not very common, admittedly. I don't understand why. I suppose some people don't like the waste of vertical space.

                                      H Offline
                                      H Offline
                                      H Brydon
                                      wrote on last edited by
                                      #37

                                      That seems to be a style used by somebody being paid per line of code ... but not somebody trying to maximize maintainability of said code...

                                      -- Harvey

                                      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