[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT - trivial programming language



"Monique Y. Mudama" <spam@bounceswoosh.org> writes:

> I may or may not feel like changing my tabwidth settings just to read
> your g*dd*mn code!

Actually, using real tabs allows us to view the same file with
different indentation levels.  However, this requires some thought
and no editor I know of applies the tabs appropriately.

What I mean is that it is possible to write C code in such a way that
it looks "good" with any tabwidth setting.  So if you prefer an
indentation step of 2, then set tabwidth to 2 and the code will be
displayed like that.  I prefer 4, so I just choose that value and get
nicer indentation that matches my taste.

The key is to distinguish between indentation and alignment.
Indentation happens after a "{" character in C-like languages and
similar constructs.  Consider the following code, which has
indentation for the middle two lines:

if (foo) {
    some_statement;
    another_statement;
}

If the middle two lines were indented with a tab, then people could
view this code with different indentation settings by just frobbing
the tab width, without changing the file contents.

Here is an example of alignment:

foo(a,
    b);

The intent is that the a and the b are beneath each other.  If the
second line is indented by a tab, then changing the tabwidth can make
the code look bad.  Therefore, the second line should start with the
right number of spaces.

It is possible and meaningful to combine indentation and alignment:

if (foo) {
    some_statement;
    foo(a,
        b);
}

The "b" line should start with one tab (for the indentation) and then
four spaces (for the alignment with the "a" above it).

I wish that Emacs would allow this style of editing.

Kai



Reply to: