[erlang-questions] Controversial subject of the day: tabs and spaces for indentation
Richard A. O'Keefe
Fri Feb 7 06:10:42 CET 2014
On 6/02/2014, at 9:21 AM, kraythe . wrote:
> Actually the solution to this age old debate was proposed to me by a friend of mine and its genius on a number of levels but isn't implemented anywhere. The reality is that for most languages whitespace is irrelevant so it shouldn't be the code holding the indentation but the user's preference file. Imagine a source code repository where there is NO irrelevant whitespace in the code base. For java, for example, there would be literally only one single line of code. Now when you check out you have a preference file that says you want tabs or spaces or mixed and also defines the other formatting you prefer. When you check out the system reformats the code according to your specs dynamically. When you commit, it strips your code of whitespace before comparing.
The IDE I use on the rare occasions that I write C# does
something not entirely unlike that. There is a bunch of
flags you can set; each comes with an example for each
alternative and you pick the one you want. It then shows
you the source code in the style you like. I have no idea
how it does this.
Of course there are languages (Occam, Haskell, Clean, Python,
...) where leading white space _does_ matter, and there are
plenty of languages (Fortran, C, APL, AWK, ...) where line
breaks matter a lot.
I suppose I can mention Interlisp-D again?
An idea that had the Xerox PARC people jumping up and down
and hugging themselves in the 80s was
A program is not a listing
it's a data base.
Source code was saved in files that were sort of readable,
but the system built indices and didn't necessarily read
them from beginning to end. Come to think of it, Smalltalk
keeps the source code on disc as a base data base + a log of
changes, keeps changes as a data structure internally, and
can be set to reindent the source code before showing it to
you (and note that this is not, per se, a change). Even the
ANSI standard format for Smalltalk source code is not really
meant for people to read and write, and as for SIXX, ...
This isn't quite the same as the proposal above, because
these systems _did_ keep white space in the data base that
wasn't strictly necessary, but they didn't/don't _depend_
on it for what they show you.
Of course this is *wonderful*, but only as long as the only
tools you want to use are the ones built into the IDE or
readily scriptable in it. Interlisp was/Smalltalk is good
at navel-gazing, but each Smalltalk is, *sigh*, different...
More information about the erlang-questions