AW: Editor Tab Expansion

Glynn Clements
Fri, 6 Dec 2002 20:47:51 +0000

Ingo Wechsung wrote:

> You have to use the :l command or the :se command in vi, for example, to
> make sure
> a) there are either only tabs or only spaces in front of the lines
> or b) the editor lets you view tabs expanded to 8.

b) is a non-issue; *every* editor lets you view tabs expanded to 8,
although some might not let you view them expanded to anything other
than 8.

There are three ways in which tabs may be handled:

a) A tab is just a character, with no concept of width.
b) Tab stops are every 8 characters, and this cannot be changed.
c) Tab stops default to being every 8 characters, although the user
can change this if they wish.

There is no option d); nothing which assigns a width to a tab
character either requires or assumes that the width is anything other
than 8.

Option c) normally equates to the user not understanding why they
shouldn't do this. Someone who thinks that it's OK to pretend that
tabs aren't 8 columns wide is someone whose experience is sufficiently
narrow that they've never encountered a situation which forcibly
dispels this delusion (e.g. where a key piece of software or hardware
falls into category b) above).

> Or, to turn it another way: "What you see is not necessarily what you get".
> This may be fine for ad hoc scripts that one examines in hugs.

Actually, one of the main benefits of layout is that the person
reading the code cannot be misled by the indentation. E.g.:

	if (foo)
		if (bar)

With layout, the compiler *will* interpret the code in the same way as
a human reading the code (unless they've specifically (mis)configured
their software to display tabs incorrectly).

If whitespace really didn't matter, then why do programmers care so
much about layout in languages where it isn't significant? (IOW, why
does "indent" exist?) Why not just write:

	if (foo)
	if (bar)

After all, you can deduce the nesting from the languages syntax,
right? Except that humans don't; they deduce the nesting from the
layout, so the layout had better match the syntactic structure or
else. OTOH, if the syntactic structure is determined by the layout,
then the two cannot fail to match.

Glynn Clements <>