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.

  • 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 '14 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 '14 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 '14 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 '14 at 13:51
  • @Clockwork-Muse Indentation was a language feature in COBOL until about 20 years ago ("A area", "B area", etc.). May 27 '14 at 12:29

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.

  • 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 '14 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 '14 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 '14 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 '14 at 13:35