Tab or No Tab :: C++ Compilers

Started by
18 comments, last by kuphryn 22 years, 2 months ago
Argh, if you set it to insert spaces then you force everyone else who looks at the code to use your indentation level... I suppose that''s better than idiotically tab aligned code...

Tabs to indent! Spaces to align! It''s really not that hard...

Tab is an ascii character (0x09), no need for binary.
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
Advertisement
Everyone should use my indentation level. My indentation is the One True Indentation.

Once there was a time when all people believed in God and the church ruled. This time is called the Dark Ages.
--AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.[Project site] [IRC channel] [Blog]
Use a code formatter like astyle.
I''m confused, as I am most of the time.

I always use tab to indent. It shouldn''t cause problems
cause whatever opens it will treat every tab the same so
the indentation should always be neat but what do you mean
by aligning stuff with spaces? If you use tabs to indent,
what''s left to do?

(I prefer tabs 8 spaces long. As far as using spaces to
indent, there''s no way I''m gonna take the time to push a
key three times when once will suffice nor take the time
to set up an IDE to do it automatically and I use the
free borland compiler which is command-line so I use
Notepad.exe)
Roland - some applications will not have your tabs as 8 spaces so the indentation will be messed up, if you indent things to match up to word lengths rather than an arbitrary number of tabs.

Having said that, I use tabs rather than spaces, and always will unless my employers decree otherwise. I find it so much easier to reformat code when it''s tabbed, and it reduces the chance of me clicking in the wrong place.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
Tabs forever!

Unfortunately I''m confused again.
quote:
Roland - some applications will not have your tabs as 8 spaces so the indentation will be messed up, if you indent things to match up to word lengths rather than an arbitrary number of tabs.

Are we talking right-justified?
Yes indeedy tabs take up a different number of spaces
depending on application and its settings, but what is this
matching to word lengths?
See Magmai''s example? If your tabs are 4 characters in size, you''d require 3 tabs and 1 space to align it like that. If your tabs are 8 characters wide, you need 1 tab and 5 spaces to align it. Now, once you''ve aligned it, change the width of your tabs, and everything gets out of alignment. Of course, you''re unlikely to change the width of your tabs, but passing the file to someone with a different setting will have this effect.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
quote:
Of course, you''re unlikely to change the width of your tabs, but passing the file to someone with a different setting will have this effect.

Or merly opening it in another editor on your machine, or on a fellow employee''s machine.

There should be the same number of tabs at the beginning of every line of indented code.

Use tabs to indent, spaces to fill-space. This is important because you use single-width characters (anything but a tab/lf/cr really) on the code above. Your own code won''t look right if you decide to change editors, or one day decide that 8spaces/tab is too many, and only want 5.

quote:
Having said that, I use tabs rather than spaces...

Arghhh, doesn''t it bother you that it only looks right for one case? When it could be right for all of them?
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
It would do, if the first thing I did with every editor wasn''t to set the tab width to 4

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
I use tabs for just about any alignment of multiple lines, and spaces for whitespace between lines.

Sometimes when I''m just doing experiments I use lots of OpenGL function calls like this:

  //I type this:glVertex3f(1.0f,---TAB---1.0f,---TAB---2.0f);glVertex3f(12.32f,-TAB---992.38,-TAB-100.2f);//so that it looks like this:glVertex3f(1.0f,         1.0f,         2.0f);glVertex3f(12.32f,       992.38,     100.2f);  


I really like the way that works.

The real problem is that people just aren''t consistant. They do things like this:
  ---TAB------TAB------TAB----cout << "Hello\n";-space--space--space--space-cout << "Godbye\n";  


If you used all tabs or all spaces, it would be fine. In this case, you chould use tabs.

So basically, I disagree with those who say don''t use tabs at all; I just maintain that you shouldn''t mix and match.

This topic is closed to new replies.

Advertisement