Chris Okasaki on Indentation Syntax

Interesting blog post by Chris Okasaki on how indentation-based syntax seemed easier for novice programmers to learn. Reddit also has some discussion of his post. Novice programming has been touched on a few times on LTU, as have usability studies for some languages.

I think Chris raises some good points which apply to experienced developers just as much as novices. In keeping with the "programs are written once, but read many times" principle, I think it's probably good to enforce indentation in some way. How that's done may be open to interpretation however. I'm interested in exploring the possibilities of indentation-based syntax. What other languages use indentation-based syntax and how does the syntax differ from Python?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


I was under the impression that Haskell optionally uses indentation in a similar manner to Python, but you can use brackets or something similar if you preferred. I don't know much Haskell though.

I find it interesting to see the kinds of things that trip up novice programmers as they so often seem to be the kinds of things I take for granted now. I seem to remember another paper that mentioned the meaning of simple assignment statements like a=b; to be an obstacle for a number of students as well. I think the paper in question was looking for early signs that a particular student would "make the cut" or not, but I don't remember its title.

That's more or less right.

That's more or less right. Haskell's syntax is specified as having delimiters, but there are also a set of standard transformation rules ("layout") which are employed by the parser to add missing delimiters based on indentation.

Most of the time, people don't bother writing explicit delimiters in Haskell, but it's still possible to write them explicitly when the occasion calls for it. I think it's a pretty nice arrangement.


Haskell uses indentation, and calls it "layout". You can use alternative syntax if you prefer.

Regarding novice programmers, maybe you're thinking of this? I'm sure there are other similar papers as well.


That is the paper I was thinking of.


The F# language has a #light syntax that is indentation based. A let bindings' scope begins at the same indentation level as the let keyword, so text doesn't crawl across the page too quickly.

-- e

OCaml as well (sort of)

Also, while not an official part of the language, there is The Whitespace Thing preprocessor for OCaml.

I-expressions in scheme

Scheme does have a quasi-official indentation based syntax via SRFI 49

This is another paper that talks about I-expressions

Very interesting

Before discussions between meaningful indentation pros and cons were mostly unproductive flamewars without much content.

So this study is very interesting..

I still prefer Ruby over Python, but that's one reason more to prefer Python to teach beginners.


For those interested in history, Peter Landin's The Next 700 Programming Languages proposed indentation based syntax for ISWIM way back in 1965.