Why do libstdc++ headers contain a mix of tabs and spaces? [closed]
Asked Answered
V

1

7

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...

Vindictive answered 12/5, 2022 at 18:53 Comment(2)
Please don't spam the tag, this question has nothing to do with c, so don't tag it as c.Ringo
It's also off-topic as C++ - it's specific to libstdc++. In any event, the reason is almost certainly that libstdc++ has a long history, with numerous developers doing edits over the years/versions. Some developers use an editing program that inserts tabs (either by default, or because they have configured it that way), some will use an editing program that inserts spaces without tabs, etc etc. A few developers might even change tabs to spaces or vice versa in the parts they have edited. The cumulative effect is jumbled mix of tabs and spaces. Such things don't affect the compiler.Footslog
U
7

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.

  1. Tabs are only used at the beginning of lines. Everything else, like ASCII art and tables, should be formatted with spaces.
  2. 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.

Unquote answered 12/5, 2022 at 20:1 Comment(5)
Why are the template lines never preceded by tabs then? Or the _M_value line? etc.Vindictive
GNU uses 8-char width tabs. That template is indented with 6 spaces, can not be indented with the tab. If you look for a deeper template, you will see tabs, example: github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/….Unquote
I can't find " _Up _M_value;", all that I have found is "\t _Up _M_value;".Unquote
@deshalder Found spaces in the 3-years old first commit. It was a code style valuation and was fixed 2 years ago with the message "libstdc++: Cleanup whitespace and type trait usage in <optional>". github.com/gcc-mirror/gcc/commit/…Unquote
Well, I see... still weird though that template lines don't have tabs, because with a smaller tab-width I'd get template lines indented instead of the content after them (because content indentation might be less than 6 bytes for example); I guess if they're using 8-space tabs, they should be using 8-space indent, but they seem to use a 2-space indent... but, okay, it kinda sorta makes sense at least; though Clang way of whitespace-only doesn't have this issue, as well as any other indentation-related issue; I don't understand why they (GCC) need to complicate/obfuscate things...Vindictive

© 2022 - 2024 — McMap. All rights reserved.