Click to See Complete Forum and Search --> : Tabs or Spaces ?


John E
November 11th, 2009, 01:34 AM
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?

VictorN
November 11th, 2009, 02:54 AM
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 ...)

John E
November 11th, 2009, 03:28 AM
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! :o 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".

Arjay
November 11th, 2009, 05:17 PM
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.

Joeman
November 11th, 2009, 06:03 PM
yeah tabs are a lot easier to deal with. code::blocks allows you to reformat the entire source code to your customized preference instantly :)

John E
November 12th, 2009, 12:22 AM
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?

Joeman
November 12th, 2009, 01:08 AM
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.

BytePtr
November 12th, 2009, 05:49 AM
Tabs. Pure and simple.

dglienna
November 16th, 2009, 07:35 PM
VS2010, with it's WPF editor. Use the mouse wheel to zoom in on code

cilu
November 17th, 2009, 08:14 AM
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.