Indenting and alignment style

a.v.reed avr at mtgzz.att.com
Wed Dec 7 02:20:10 AEST 1988


The real issue is readability. I think even Henry Spencer would agree
that the goal is to make code as easy to read and understand as
possible. This in turn is influenced by matching style to the human
visual system and mind - objective readability - and by how close the
style is to what one is used to. Objective readability (on which there
is a vast literature in psychology, human factors and education
journals) suggests that the optimal style would provide the reader with
vertical alignment of the closing brace with the opening brace, and of
immediately enclosed text with the enclosed braces, like this:

	function(argument,argument)
		{
		statement;
		statement;
		}

If everyone were starting from scratch, this would be readily accepted
by everyone. But since that is not the case, we have to deal with the
fact that objective readability does not necessarily optimize relative
readability, especially for individuals who are used to (and have what
psychologists call "overlearned skills" for processing) an objectively
suboptimal but, in the C community, traditional style:

	function(argument,argument){
		statement;
		statement;
	}

With this style, the reader cannot use vertical alignment for conceptual
matching, either between the corresponding opening and closing brace, or
between the braces and the text they enclose. But people who have been
reading code in this style for many years have developed compensating
skills, and insist that vertically aligned code is "difficult to read" or
even "ugly". And for/to them, it certainly is.

The solution, I think, is to write code in the style that's best for
you, and use "prettyprinting" tools when reading or editing code written
in a different style by somebody else. That way, new programmers can
learn the (objectively optimal) vertically aligned style without unduly
inconveniencing the "old dogs" and traditionalists. After all, *tools*
are why we use UNIX(R) and C in the first place. Insisting that everyone
conform to what you happen to like and/or are used to isn't just
religion, it is neanderthal religion. It'll make you miserable. So just
filter the code you read through the prettyprinter of your choice, and
be happy. OK?
				Adam Reed (avr at mtgzz.ATT.COM)



More information about the Comp.unix.wizards mailing list