CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com

View Poll Results: What kind of text alignment do you prefer?

Voters
8. You may not vote on this poll
  • I (or my employer) prefer alignment using tabs

    3 37.50%
  • I (or my employer) prefer alignment using spaces

    3 37.50%
  • I / we need a mixture of both

    1 12.50%
  • I / we have no preference

    1 12.50%
Results 1 to 10 of 10
  1. #1
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Tabs or Spaces ?

    These days I've noticed that a lot of code editors have the option to expand tabs (on opening a source file) and replace them with space characters - i.e. if you open the source file, you'll now have (say) four spaces wherever you used to have a tab. What's the general preference nowadays? Tabs or spaces?
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,430

    Re: Tabs or Spaces ?

    Well, such an option (to expand tabs) exists since at least 3 or more decades. I used it in ME editor (I replaced tabs with spaces) while writing FORTRAN code.
    Now I use Tabs for alignments. I use, however, spaces as a separator (after commas, around < > = signs and so on ...)
    Victor Nijegorodov

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Re: Tabs or Spaces ?

    Quote Originally Posted by VictorN View Post
    Well, such an option (to expand tabs) exists since at least 3 or more decades.
    Really? I only started noticing it a few years ago! For my own programs I've started to prefer using spaces for indentation, rather than tabs but it can be quite annoying when working on a collaborative project. Many 'diff' programs aren't intelligent enough to ignore differences in indentation (and of course, there are programming languages where indentation is important). So for a collaborative project, I just have to "go with the flow".
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Tabs or Spaces ?

    My preference is for using tabs; however, many source code tools can't handle the tabs, so often times using spaces is required.

    I go with the flow on projects like that but it makes backspacing more of a pain.

    One thing cool with an editor like Visual Studio (2005 or higher) is that you can set up your preferences for indentation, spaces, tabs, curly braces and so forth and the code with auto format upon block or statement completion. You can also format the selection or the whole document. If you work as a team you can just pass around the preferences file (by exporting the settings) to other team members. Then you really don't need to go over formatting as much in code reviews.

  5. #5
    Join Date
    Jun 2008
    Posts
    592

    Re: Tabs or Spaces ?

    yeah tabs are a lot easier to deal with. code::blocks allows you to reformat the entire source code to your customized preference instantly
    0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
    0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000
    0000 0000 0000 0000

  6. #6
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Re: Tabs or Spaces ?

    Joeman - could you tell me how to do that in Code::Blocks?

    Funnily enough, it was C::B that brought this to mind for me. I upgraded it about a month ago and for the past month it's been relentlessly turning all my tabbed indentations into spaces. For my own projects I found that I actually prefer spaces but for collaborative projects it's been a royal PITA.

    I found a setting that would stop C::B from doing it in future but I didn't see a way to undo the damage it's already done - i.e. a way to change every (say) 4 spaces, into an indent. Is that possible?
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  7. #7
    Join Date
    Jun 2008
    Posts
    592

    Re: Tabs or Spaces ?

    I haven't really needed to try to go back and forth from spaces to tabs. However I believe all you need to do is go under the menu to editor, scroll down to source formatter in the left column list, click customize, go under the tab called Indentation and select "Use TABs instead of spaces" and "Force using TABs". These are probably selected already. After that, run the source formatter plugin.

    If this doesn't work, perhaps just turning on Backspace unindents would suffice.
    0100 0111 0110 1111 0110 0100 0010 0000 0110 1001 0111 0011 0010 0000 0110 0110 0110 1111 0111 0010
    0110 0101 0111 0110 0110 0101 0111 0010 0010 0001 0010 0001 0000 0000 0000 0000
    0000 0000 0000 0000

  8. #8
    Join Date
    May 2005
    Location
    Estonia
    Posts
    235

    Re: Tabs or Spaces ?

    Tabs. Pure and simple.
    Rate my post if i it was useful!

  9. #9
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Tabs or Spaces ?

    VS2010, with it's WPF editor. Use the mouse wheel to zoom in on code
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  10. #10
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Tabs or Spaces ?

    The convention in my company is that we use spaces instead tabs. No everybody complies though. I don't know which are to be preferred. I can work with both. But I don't like when different people in the same team use different conventions because that messes the source files.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured