git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: Christer Weinigel <christer@weinigel.se>
Cc: Tom Tobin <korpios@korpios.com>, git@vger.kernel.org
Subject: Re: On Tabs and Spaces
Date: Tue, 16 Oct 2007 17:45:51 -0700 (PDT)	[thread overview]
Message-ID: <alpine.LFD.0.999.0710161722320.26902@woody.linux-foundation.org> (raw)
In-Reply-To: <20071017015109.303760cc@localhost.localdomain>



On Wed, 17 Oct 2007, Christer Weinigel wrote:
> 
> If you assume that everyone is sane and use a tab size of 8 you will
> get bitten, sooner or later.  Or actually, you, Linus, who are lucky
> enough to work mostly with Linux source, you might personally not get
> bitten all that often.  But us poor suckers that have to work with
> other people, often Windows programmers, we do.

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.

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

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.

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 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"?

			Linus

  reply	other threads:[~2007-10-17  0:46 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-16  6:45 On Tabs and Spaces Michael Witten
2007-10-16  7:04 ` Shawn O. Pearce
2007-10-16  7:27   ` Michael Witten
2007-10-16 17:20     ` Andreas Ericsson
2007-10-16 17:40       ` Sam Ravnborg
2007-10-16 23:09         ` Petr Baudis
2007-10-17  3:41           ` David
2007-10-17 11:32             ` Andy Parkins
2007-10-16  8:30 ` Adam Piatyszek
2007-10-16  9:04   ` Lars Hjemli
2007-10-16 10:16     ` Adam Piatyszek
2007-10-16 15:26       ` Jeffrey C. Ollie
2007-10-16 15:51         ` Michael Witten
2007-10-16 17:06           ` Jari Aalto
2007-10-16 19:20             ` Linus Torvalds
2007-10-16 19:36               ` Mike Hommey
2007-10-16 19:47                 ` Linus Torvalds
2007-10-16 19:51                   ` Linus Torvalds
2007-10-16 20:32                   ` Matthieu Moy
2007-10-16 20:18               ` Tom Tobin
2007-10-16 23:05                 ` Linus Torvalds
2007-10-16 23:51                   ` Christer Weinigel
2007-10-17  0:45                     ` Linus Torvalds [this message]
2007-10-17  3:08                       ` Michael Witten
2007-10-17  3:29                         ` Linus Torvalds
2007-10-17  7:17                       ` Luke Lu
2007-10-17  9:09                         ` Michael Witten
2007-10-17 10:03                           ` Luke Lu
2007-10-17 10:21                           ` Nikolai Weibull
2007-10-17 11:23                             ` Michael Witten
2007-10-17 22:02                           ` Jari Aalto
2007-10-17 22:36                             ` Andreas Ericsson
2007-10-17 23:38                               ` Jari Aalto
2007-10-18  4:31                                 ` Dmitry Torokhov
2007-10-18  8:19                                   ` Jari Aalto
2007-10-18 11:34                                     ` Petr Baudis
2007-10-18 11:39                                       ` Nikolai Weibull
2007-10-22  3:39                                         ` Miles Bader
2007-10-18  7:15                               ` David Kågedal
2007-10-18  5:42                             ` Mike Hommey
2007-10-18 10:36                               ` Jari Aalto
2007-10-17 15:53                         ` Linus Torvalds
2007-10-17 18:05                           ` Johannes Schindelin
2007-10-17 18:25                           ` Tom Tobin
2007-10-17 18:54                             ` Linus Torvalds
2007-10-17 19:33                               ` Tom Tobin
2007-10-17 19:44                                 ` Linus Torvalds
2007-10-17 19:48                                 ` Nicolas Pitre
2007-10-17 19:52                                 ` Josh England
2007-10-17 19:53                                 ` Linus Torvalds
2007-10-17 21:21                                   ` Christer Weinigel
2007-10-17 22:03                                     ` Linus Torvalds
2007-10-18  6:25                                       ` David Kastrup
2007-10-17 22:11                                     ` Johannes Schindelin
2007-10-17 23:17                                       ` Christer Weinigel
2007-10-17 23:44                                         ` Johannes Schindelin
2007-10-18  0:31                                           ` Christer Weinigel
2007-10-18  6:02                                             ` Andreas Ericsson
2007-10-18  7:12                                             ` David Kågedal
2007-10-17 23:53                                         ` Linus Torvalds
2007-10-17 20:31                                 ` David Kastrup
2007-10-17 21:08                                 ` Johannes Schindelin
2007-10-17 19:47                               ` Jan Wielemaker
2007-10-18  0:32                           ` Jeff King
2007-10-18  0:59                             ` Linus Torvalds
2007-10-18  2:45                               ` Jeff King
2007-10-18  3:03                                 ` david
2007-10-18  3:00                                   ` Jeff King
2007-10-18  3:32                                     ` Linus Torvalds
2007-10-18  4:17                                       ` Linus Torvalds
2007-10-18  3:13                                 ` Linus Torvalds
2007-10-18  3:23                                   ` Jeff King
2007-10-18  4:41                                     ` [PATCH] Add a message explaining that automatic GC is about to start koreth
2007-10-18  4:44                                       ` Steven Grimm
2007-10-18  5:01                                       ` Jeff King
2007-10-18  5:11                                         ` Shawn O. Pearce
2007-10-18 13:52                                       ` Brian Gernhardt
2007-10-18 14:16                                         ` Steven Grimm
2007-10-18 18:08                                           ` Jeff King
2007-10-19  0:16                                           ` Shawn O. Pearce
2007-10-19  1:12                                             ` [PATCH] git-gc: improve wording of --auto notification Jeff King
2007-10-19  1:24                                               ` Shawn O. Pearce
2007-10-19  1:26                                                 ` Jeff King
2007-10-18 14:21                                         ` [PATCH] Add a message explaining that automatic GC is about to start Nicolas Pitre
2007-10-18  4:52                                 ` On Tabs and Spaces Nicolas Pitre
2007-10-18  4:54                                   ` Jeff King
2007-10-18  4:55                                     ` Jeff King
2007-10-17 16:08                         ` David Kastrup
2007-10-17 17:44                           ` Nicolas Pitre
2007-10-17 19:52                             ` David Kastrup
2007-10-17 17:51                           ` Sean
2007-10-17  5:56                   ` David Kastrup
2007-10-16 20:56               ` Sam Ravnborg
2007-10-18  3:31               ` Paul Wankadia
2007-10-18  4:22                 ` Linus Torvalds
2007-10-18  4:36               ` Dmitry Potapov
2007-10-16 17:23         ` Andreas Ericsson
2007-10-16 18:34           ` Jan-Benedict Glaw
2007-10-16 18:51             ` Andreas Ericsson
2007-10-20 13:54 ` Robin Rosenberg

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LFD.0.999.0710161722320.26902@woody.linux-foundation.org \
    --to=torvalds@linux-foundation.org \
    --cc=christer@weinigel.se \
    --cc=git@vger.kernel.org \
    --cc=korpios@korpios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).