31

I am interested in finding out who introduced code indentation, as well as when and where it was introduced.

It seems so critical to code comprehension, but it was not universal. Most Fortran and Basic code was (is?) unindented, and the same goes for Cobol.

I am pretty sure I have even seen old Lisp code written as continuous, line-wrapped text. You had to count brackets in your head just to parse it, never mind understanding it.

So where did such a huge improvement come from? I have never seen any mention of its origin.

Apart from original examples of its use, I am also looking for original discussions of indentation.

5
  • I'm not sure it has a single point of origin. Also, for some early code, the space taken up by the spaces themselves would have been an issue. May 22, 2014 at 14:09
  • 1
    Actually, FORTRAN was indented. In sorts. It was laid out in columns, the first being reserved for the C character if you were making a comment. May 22, 2014 at 14:26
  • Barring cases where indentation is used to change the semantic meaning of code (that is, where changing indentation will put it in loops or as part of an if, a la F#), indentation isn't really a language feature, it's an IDE feature (and a bit in the compiler, to ignore leading spaces). @Jack's right - originally programs were punched on cards, and indentation literally didn't exist in the storage (and perhaps shouldn't now, either). Columnar RPG doesn't use indentation (and you only have ~20 characters free per line anyways), but the IDE can "soft" indent the code for you. May 23, 2014 at 13:42
  • 8
    Thinking about this overnight, it occurs to me that to a meaningful degree indentation probably predates programming. Indentation was likely used in instruction lists prior to anyone writing computer programs. I'm trying to hunt down an example. May 23, 2014 at 13:51
  • @Clockwork-Muse Indentation was a language feature in COBOL until about 20 years ago ("A area", "B area", etc.). May 27, 2014 at 12:29

3 Answers 3

21

The origins of indented code probably can be found in ALGOL:

ALGOL introduced code blocks and the begin and end pairs for delimiting them and it was also the first language implementing nested function definitions with lexical scope.

4
  • That sounds reasonable, though I wonder if Lisp's progn may not have come first. Either way I am really after specifics on the introduction of indentation. May 22, 2014 at 7:47
  • 4
    @DanielMahler - Browse the LISP 1 programming manual and see for yourself. Some of the example code is indented, but it's haphazard at best. Most of the example code is flush left. May 22, 2014 at 11:30
  • @DavidHammen That must've been one of the worst typewriters...You would've thought they just handwrote the whole thing. May 22, 2014 at 16:07
  • 6
    I don't think the quoted text actually supports the use/existence of indentation. That's support for sectioning code. Java uses brackets ({}) to delimit blocks, and you can define nested functions, but that doesn't tell me anything about whether the code is actually indented. May 23, 2014 at 13:35
12

Indented code must have arrived prior to 1958, since it was present - but not ubiquitous - in LISP and ALGOL. The earliest I can locate is COMTRAN which was introduced in 1957, although I can only find the 1960 manual only (see page 90ish). This indentation differs from the modern conception since COMTRAN lacks the block structure of most languages since ALGOL but I think it should still count.

I suspect that this is not actually the first example but I cannot locate any earlier.

Updated

It has occurred to me that to a meaningful degree indentation probably predates programming. Indentation was likely used in instruction lists prior to anyone writing computer programs. Unfortunately I can't find any good examples of this.

-1

An expansion on Ross Patterson's comment - COBOL compilers (or at least IBM's compilers, which I used in my pre-open systems career) enforced indentation (the "A" and "B" areas he mentions). If any of the elements that were required to be in these areas were not placed exactly, your code would fail compilation. However, beyond that no specific indentation was required - this often led to griping when modifying the code of another developer whose indentation style was different than yours - etiquette would suggest you follow the existing pattern as that preserved peace among peers; additionally, different styles in the same source would be aggravating to view, almost Tetris-like in appearance.

It's been years since I've thought about COBOL and its indentation - thanks for asking the question and providing a little trip to the past!

Marty

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.