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

Re: On Tabs and Spaces

From
LLLuke Lu <git@vicaya.com>
Date
Oct 17, 2007, 07:17 UTC
Message-ID
<3A9408D5-2667-43A6-A0CE-C0720B3A3987@vicaya.com>
In-Reply-To
<alpine.LFD.0.999.0710161722320.26902@woody.linux-foundation.org>
I'm late in this game. But it's too classic a debate to miss the fun.
On Oct 16, 2007, at 5:45 PM, Linus Torvalds wrote:
Show 19 quoted lines
> One issue may well be that Windows programmers also probably don't  
> work
> very much with patches, do they?
>
> One reason for *really* wanting to use hard-tabs is that it makes  
> patches
> look better, exactly because diffs contain that one extra (or two,  
> in the
> case of old-style context diffs) character at the beginning of the  
> line.
>
> Which means that while all-space indents look fine, *mixing* styles
> definitely does not. In particular, a two-character indent (which
> hopefully nobody uses, but people are crazy) will be totally  
> unreadable as
> a patch if you have the (fairly common, at least in UNIX projects)  
> style
> of using spaces for less-than-eight-character-indents and tabs for the
> full 8 characters.

Yes, all-space would look fine in patches. It'll look better than all tabs for tables and ascii formula and diagrams in comments, as one prepended character could screw up the tabs (depending on the content), rendering them totally unreadable. In all-space case, things just shift to the right by one character column.

I believe the indentation convention for ruby is 2 spaces. It looks tight to me :)

Show 11 quoted lines
> (In particular, a 3-level and 4-level indent will look *identical*  
> in such
> a project, when using context diffs).
>
> And sure, you can use all-spaces-everywhere, but that just isn't  
> what any
> normal UNIX editors are set up for by default. In contrast, under  
> UNIX, I
> can pretty much guarantee that hard-tab indents look at least  
> reasonable
> in any editor.

But all-space would look perfect in any editor as the authors intended, including the tables and ascii arts, as long as it's using monospace font. It's easy to setup all space editing on all platforms (Windows, Mac, *nix) It's also much easier to enforce. I've used pre- commit hook to check for tabs in the source and reject them if a tab is found :)

Show 9 quoted lines
> And if you have an editor that shows hard-tabs as 4-character indents,
> generally you can work with it. You may have odd indentation, and  
> people
> may complain about your patches not lining up, and yes, it would be  
> up to
> *you* to understand that 8-wide tabs are the normal and default.  
> But you
> can certainly work with a source base that uses a single hard-tab for
> indentation.
> In contrast, if you use spaces (or worse - mixing), things really look
> ugly as sin, to the point of actually being unworkable.
>
Well, we just established that all-space is perfect, look-wise.
Show 20 quoted lines
> In short:
>
>  - if the project has the rule that an indentation is "one hard- 
> tab", then
>    at least everybody can *work* with that project. Different  
> people may
>    see things laid out slightly differently, but it's generally not a
>    horrible disaster, especially if you aim to use block comments  
> indented
>    with the code (like we *mostly* do both in the kernel and in git)
>
>  - all-space and all-tabs just leads to problems. Yes, I know about
>    python, but lets face it, python is different, since the spacing  
> has
>    semantic rules there. Most non-python programmers will not use  
> editors
>    where you can obviously see the difference between spaces and  
> tabs, and
>    as a result an all-space model will *turn* into a mixed-space/tab
>    model, and you get horrible end results.
As I mentioned, an all-space policy is trivial to enforce.
Show 41 quoted lines
>  - as per above, mixing spaces and tabs is a *horrid* idea.
>
>  - as a result, a "pure tab for indents" model tends to be workable in
>    most situations. It may not be ideal for you, but it's workable.
>
>  - and at least in the UNIX world, default for pure tabs really is 8
>    characters. Even if you have an editor that shows them as four,  
> you'll
>    see different results outside the editor (eg "grep -5 file.c"), so
>    people should just consider other tab sizes to be "secondary".
>
>    And as long as 99% of all git developers are under Linux, and  
> all the
>    core ones seem to have had no problem with the current tab rules, I
>    really don't see why that should change.
>
> See? Hard-tabs are good. Maybe Windows people don't ever see patches
> (perhaps they only see them as side-by-side graphical things), and  
> maybe
> windows projects are always done inside *one* environment where  
> there is
> no "grep" and "terminal TAB size" and "fifty different editors with
> different defaults".
>
> But even in DOS/Windows, hard-tabs seem to be quite common, judging by
> what little source code I've seen from Windows projects.
>
> And I just checked. The current git model seems to work fine if you  
> have
> an editor that thinks tabs are 4 spaces:
>
> 	sed 's/	/    /g' < revision.c  | less -S
>
> (that's a hard-tab in that first regex). No, things don't  
> necessarily line
> up just like they should, but you actually have to *look* for  
> problems to
> see them (ie stuff where people have added line-breaks).
>
> And is it really so unreasonable to just say "8-character tabs are the
> gold standard"?

But I still haven't seen any compelling arguments against the "all space" case, other than "people will screw it up into mixed spaces", which is really a straw man, as many multi-platform projects enforced the all-space policy easily by using a pre-commit hook in maintainers' repository.

The only downside of all-space is a moderate space bloat in source, which is insignificant, all things considered.

I agree that "8-character tabs are the gold standard", only for the tabstop==8 part but not the indent==tab part. For me the question is: is it really so unreasonable to just say "all-space is the holy grail"?

__Luke
Previous: Linus TorvaldsNext: Michael Witten
Message 26 of 100 in “On Tabs and Spaces”
  1. Michael WittenOct 16, 2007
  2. Shawn O. PearceOct 16, 2007
  3. Michael WittenOct 16, 2007
  4. Andreas EricssonOct 16, 2007
  5. Sam RavnborgOct 16, 2007
  6. Petr BaudisOct 16, 2007
  7. DavidOct 17, 2007
  8. Andy ParkinsOct 17, 2007
  9. Adam PiatyszekOct 16, 2007
  10. Lars HjemliOct 16, 2007
  11. Adam PiatyszekOct 16, 2007
  12. Jeffrey C. OllieOct 16, 2007
  13. Michael WittenOct 16, 2007
  14. Jari AaltoOct 16, 2007
  15. Linus TorvaldsOct 16, 2007
  16. Mike HommeyOct 16, 2007
  17. Linus TorvaldsOct 16, 2007
  18. Linus TorvaldsOct 16, 2007
  19. Matthieu MoyOct 16, 2007
  20. Tom TobinOct 16, 2007
  21. Linus TorvaldsOct 16, 2007
  22. Christer WeinigelOct 16, 2007
  23. Linus TorvaldsOct 17, 2007
  24. Michael WittenOct 17, 2007
  25. Linus TorvaldsOct 17, 2007
  26. Luke LuOct 17, 2007
  27. Michael WittenOct 17, 2007
  28. Luke LuOct 17, 2007
  29. Nikolai WeibullOct 17, 2007
  30. Michael WittenOct 17, 2007
  31. Jari AaltoOct 17, 2007
  32. Andreas EricssonOct 17, 2007
  33. Jari AaltoOct 17, 2007
  34. Dmitry TorokhovOct 18, 2007
  35. Jari AaltoOct 18, 2007
  36. Petr BaudisOct 18, 2007
  37. Nikolai WeibullOct 18, 2007
  38. Miles BaderOct 22, 2007
  39. David KågedalOct 18, 2007
  40. Mike HommeyOct 18, 2007
  41. Jari AaltoOct 18, 2007
  42. Linus TorvaldsOct 17, 2007
  43. Johannes SchindelinOct 17, 2007
  44. Tom TobinOct 17, 2007
  45. Linus TorvaldsOct 17, 2007
  46. Tom TobinOct 17, 2007
  47. Linus TorvaldsOct 17, 2007
  48. Nicolas PitreOct 17, 2007
  49. Josh EnglandOct 17, 2007
  50. Linus TorvaldsOct 17, 2007
  51. Christer WeinigelOct 17, 2007
  52. Linus TorvaldsOct 17, 2007
  53. David KastrupOct 18, 2007
  54. Johannes SchindelinOct 17, 2007
  55. Christer WeinigelOct 17, 2007
  56. Johannes SchindelinOct 17, 2007
  57. Christer WeinigelOct 18, 2007
  58. Andreas EricssonOct 18, 2007
  59. David KågedalOct 18, 2007
  60. Linus TorvaldsOct 17, 2007
  61. David KastrupOct 17, 2007
  62. Johannes SchindelinOct 17, 2007
  63. Jan WielemakerOct 17, 2007
  64. Jeff KingOct 18, 2007
  65. Linus TorvaldsOct 18, 2007
  66. Jeff KingOct 18, 2007
  67. david@lang.hmOct 18, 2007
  68. Jeff KingOct 18, 2007
  69. Linus TorvaldsOct 18, 2007
  70. Linus TorvaldsOct 18, 2007
  71. Linus TorvaldsOct 18, 2007
  72. Jeff KingOct 18, 2007
  73. Add a message explaining that automatic GC is about to startkoreth@midwinter.com, Oct 18, 2007
  74. Steven GrimmOct 18, 2007
  75. Jeff KingOct 18, 2007
  76. Shawn O. PearceOct 18, 2007
  77. Brian GernhardtOct 18, 2007
  78. Steven GrimmOct 18, 2007
  79. Jeff KingOct 18, 2007
  80. Shawn O. PearceOct 19, 2007
  81. git-gc: improve wording of --auto notificationJeff King, Oct 19, 2007
  82. Shawn O. PearceOct 19, 2007
  83. Jeff KingOct 19, 2007
  84. Nicolas PitreOct 18, 2007
  85. Nicolas PitreOct 18, 2007
  86. Jeff KingOct 18, 2007
  87. Jeff KingOct 18, 2007
  88. David KastrupOct 17, 2007
  89. Nicolas PitreOct 17, 2007
  90. David KastrupOct 17, 2007
  91. SeanOct 17, 2007
  92. David KastrupOct 17, 2007
  93. Sam RavnborgOct 16, 2007
  94. Paul WankadiaOct 18, 2007
  95. Linus TorvaldsOct 18, 2007
  96. Dmitry PotapovOct 18, 2007
  97. Andreas EricssonOct 16, 2007
  98. Jan-Benedict GlawOct 16, 2007
  99. Andreas EricssonOct 16, 2007
  100. Robin RosenbergOct 20, 2007

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.