I've been looking at libstdc headers for a few years now, and I was always surprised about how weirdly it mixes tabs and spaces, e.g. something like:
template<typename _Up, typename... _Args>
<tab >constexpr
<tab >_Optional_payload_base(std::initializer_list<_Up> __il,
<tab ><tab ><tab > _Args&&... __args)
<tab >: _M_payload(__il, std::forward<_Args>(__args)...),
<tab > _M_engaged(true)
<tab >{ }
<...>
<tab > _Empty_byte _M_empty;
_Up _M_value;
<tab >};
template<typename _Up>
<tab >union _Storage<_Up, false>
<tab >{
Why is there a random mix of tabs and spaces even within the same line?
It becomes even more confusing when viewing with a non-8 tab display setting (which I guess a lot of users might have...).
libc headers OTOH look just fine (no tabs AFAIR)...
Obviously this would be an opinion-based question if it were just about tabs vs. spaces, but this is a mix of both... I thought it's never a good idea and didn't see it anywhere except libstdc I think...
CodePudding user response:
This is the usual old-school smart tab indentation for saving disk space and faster transfer speed between devices in ancient times prior USB. Also matrix needle printers performed faster carriage moving on a single tab symbol in comparison with moving on 4 or 8 spaces.
- Tabs are only used at the beginning of lines. Everything else, like ASCII art and tables, should be formatted with spaces.
- Tabs are only used for expressing the indentation level. One tab per “block” – any remaining whitespace is spaces only.
List items are the quotes got from the fanny articles SmartTabs and Indent with tabs, align with spaces.
CodePudding user response:
So, apparently there is some GNU coding standard that, among other things, specifies that any heading octets of spaces shall be replaced by tabs.
However, judging by this line above (from GCC 10, without any tabs):
_Up _M_value;
this rule can also be violated.
In short, it appears that GNU is just pretty stubbrn to keep both, despite the fact that might hurt developers reading standard library headers:
- tabs are not always set to 8 spaces by default
- you have to remember to reset them to 8 every time you switch to new env
- non-8-space tab might be used (and forced, e.g. in a way similar to this) elsewhere in the project(s)
- there are web and other tools where one cannot control tab size
etc.
Welp.