git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH RFC3 09/13] send-email: Remove horrible mix of tabs and spaces

From
Michael Witten <mfwitten@gmail.com>
Date
Apr 14, 2009, 07:03 UTC
Message-ID
<27f7c25b-7bdc-40d1-a601-bd162ebbe2f2@gmail.com>
In-Reply-To
<49E41F99.6010409@op5.se>
On Tue, Apr 14, 2009 at 00:31, Andreas Ericsson <ae@op5.se> wrote:
Show 28 quoted lines
> Michael Witten wrote:
>>
>> On Mon, Apr 13, 2009 at 15:55, Junio C Hamano <gitster@pobox.com> wrote:
>>>
>>> Michael Witten <mfwitten@gmail.com> writes:
>>>
>>>> Currently, no lines match the following:
>>>>
>>>>    [\t]+[ ]+
>>>>    [ ]+[\t]+
>>>
>>> I understand the latter but what's wrong with the former?  The width of a
>>> HT is by definition 8 columns throughout the git codebase.
>>
>> Ah, well, the width of a HT has been a free variable in my
>> calculations; I was operating under the assumption that whitespace
>> used for indentation can float freely according to the user's
>> settings. A few of the lines were aligning function arguments via tabs
>> and a few extra spaces, which is not reliable in my model.
>>
>> Frankly, I don't like tabs and spaces sharing the same contiguous
>> block. I don't like it all. ;-B
>
> Using tabs to align stuff to indentation level and spaces to align
> line continuation is the only possible way to let users choose
> whichever indentation depth they want while preserving the continuation
> alignment. What's not to like about that? Especially if you think a
> horizontal tab can be any size at all, you should be all agog.

However, nobody ever gets that right, because they don't understand what you mean by indentation level. For most code that people write, indentation whitespace overlaps with non-whitespace (from the previous line). Therefore, the spaces used for continuation alignment with the previous line are left 'sitting on shaky ground'. For instance, consider this fine piece of code, given by lines 609-612 in builtin-log.c. If you're viewing this code with a monospace font and HT set to 8 columns, then the tab->spaces expansion should give the following result (monospace font required to view this properly):

static void make_cover_letter(struct rev_info *rev, int use_stdout,
                              int numbered, int numbered_files,
                              struct commit *origin,
                              int nr, struct commit **list, struct commit *head)
Beautiful, isn't it?

In this case, we're at indentation level ---> 0 <---, and this means that to form the continuation alignment, 0 tabs should be used followed by however many spaces are needed to achieve the alignment. However, whoever wrote that code actually used indentation level 3:

<HT><HT><HT><SP><SP><SP><SP><SP><SP>

The problem is that variable-width characters (HTs) are being aligned with fixed-width characters. For shame!

To be explicit, if the HT width is set to 4, the result would be (after HT->spaces expansion):

static void make_cover_letter(struct rev_info *rev, int use_stdout,
                  int numbered, int numbered_files,
                  struct commit *origin,
                  int nr, struct commit **list, struct commit *head)

Clearly, this is never a problem if you declare HTs to be fixed-width (which, I believe, Linus did do: 8 columns per HT), or if you can remember that HTs should never be used to align against non-HTs.

What I like to do is provide a more regular structure that removes the juxtaposition of indentation and alignment whitespace. Basically, HTs and spaces should never be contiguous, and the first use of a non-HT prohibits HTs from being used anywhere further down the line. Also, the structure of the code should facilitate identation levels:

static void make_cover_letter
(
	/* These are all at indentation level 1 */
	struct rev_info* rev            ,
	int              use_stdout     ,
	int              numbered       ,
	int              numbered_files ,
	struct commit*   origin         ,
	int              nr             ,
	struct commit**  list           ,
	struct commit*   head
)
{
	/* Code at indentation level 1 */
}
Yeah, yeah, I know it's crazy, but it makes code wildly readable---to me.

Sincerely, Michael Witten

Previous: Andreas EricssonNext: Andreas Ericsson
Message 20 of 39 in “I hope this will do it!”
  1. I hope this will do it!Michael Witten, Apr 13, 2009
  2. 01/13 Docs: send-email: Put options back into alphabetical orderMichael Witten, Apr 13, 2009
  3. 02/13 Docs: send-email: Refer to CONFIGURATION section for sendemail.multieditMichael Witten, Apr 13, 2009
  4. 03/13 Docs: send-email: Remove superfluous information in CONFIGURATIONMichael Witten, Apr 13, 2009
  5. 04/13 Docs: send-email: --smtp-server-port can take symbolic portsMichael Witten, Apr 13, 2009
  6. 05/13 send-email: Cleanup the usage text and docs a bitMichael Witten, Apr 13, 2009
  7. 06/13 send-email: Handle "GIT:" rather than "GIT: " during --composeMichael Witten, Apr 13, 2009
  8. 07/13 send-email: 'References:' should only reference what is sentMichael Witten, Apr 13, 2009
  9. 08/13 send-email: Remove superfluous `my $editor = ...'Michael Witten, Apr 13, 2009
  10. 09/13 send-email: Remove horrible mix of tabs and spacesMichael Witten, Apr 13, 2009
  11. 10/13 send-email: Add --sleep for email throttlingMichael Witten, Apr 13, 2009
  12. 11/13 send-email: Minor cleanup of $smtp_server usage and send_message()Michael Witten, Apr 13, 2009
  13. 12/13 send-email: --compose takes optional argument to existing fileMichael Witten, Apr 13, 2009
  14. 13/13 send-email: --compose always includes a 'GIT: ' prefixed list of patch subjectsMichael Witten, Apr 13, 2009
  15. Junio C HamanoApr 13, 2009
  16. Michael WittenApr 13, 2009
  17. Andreas EricssonApr 14, 2009
  18. Junio C HamanoApr 14, 2009
  19. Andreas EricssonApr 14, 2009
  20. Michael WittenApr 14, 2009
  21. Andreas EricssonApr 14, 2009
  22. Stephen BoydApr 13, 2009
  23. Michael WittenApr 14, 2009
  24. Michael WittenApr 14, 2009
  25. Björn SteinbrinkApr 14, 2009
  26. Junio C HamanoApr 14, 2009
  27. Junio C HamanoApr 13, 2009
  28. Michael WittenApr 13, 2009
  29. Junio C HamanoApr 14, 2009
  30. Michael WittenApr 14, 2009
  31. Junio C HamanoApr 14, 2009
  32. Michael WittenApr 14, 2009
  33. Junio C HamanoApr 13, 2009
  34. Michael WittenApr 13, 2009
  35. Michael WittenApr 13, 2009
  36. Junio C HamanoApr 14, 2009
  37. Michael WittenApr 14, 2009
  38. Junio C HamanoApr 14, 2009
  39. Michael WittenApr 14, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.