The Knuth Indentation Quote rediscovered

by Uche Ogbuji

Related link:

We will perhaps eventually be writing only small modules which are identified by name as they are used to build larger ones, so that devices like indentation, rather than delimiters, might become feasible for expressing local structure in the source language.

--Donald E. Knuth, "Structured Programming with goto Statements", Computing Surveys, Vol 6 No 4, Dec. 1974

I love to tell people how I discovered Python. I was just getting into Red Hat, back in late 1996 (Red Hat 4.0, if I remember correctly). I was using the printer set-up UI and it broke, leaving a traceback to the screen. I remember on a lark following the traceback to the source file, which was in a languae I hadn't heard of. Reading the section of code around the reported failure, and after a bit of trial and error, I was able to fix the bug and that got the printer applet working again. I don't remember the details, but I believe it was a misplaced variable assignment in one of the code branches.

I did not look at a single reference on Python during that incident. I was pretty much blown away at how clear the language was, and I've been a strong Python user and advocate ever since then. But this discusson is about indentation The funny thing is that I didn't learn that Python required indentation until I later on read the Python tutorial, trying to get properly into the language. Even then, I don't recall that, that detail caused me a moment's pause.

When I was working on the printer GUI, through all my trial and error I always just naturaly followed the indentation that was in the code module. I was a C++ guy at the time (and just beginning to learn that things were deeply amiss with Java) and everywhere I'd ever worked, your code would be rejected upon review if you didn't meet code standards, of which indentation was a prominent part. For this enforcement to come from the language rather than peer review seemed a natural progression.

I remember the Knuth Indentation Quote (KIQ) coming up in the Python community. There was some talk a few years ago in the Python Software Association of putting it on a T-shirt for sale (I don't believe thre was ever such a T-shirt designed but one of the IPC T-shirts hadd the motto "Life's better without braces"). I never really appeciated the quote because I always felt that I'd rather advocate Python based on serious considerations of expressiveness and flexibility rather than combating what I hold to be frivolities. And I didn't really know the context of the KIQ.

Now Python has firmly entered the mainstream. There are still people who make an amazing amount of noise about a syntactic feature that enforces clarity. Over the years I've heard many criticisms of Python, many which have been very valid, and many of those which have since been addressed. This included poor Unicode support, lack of closures, tendency towards memory leaks and speed. I have never taken anyone seriously who held the indentation as a serious defect in Python, and so I might as well use the KIQ as the light-hearted tool it is. In future, rather than rolling my eyes the next time someone says "Ewww. Significant whitespace", I'll just smile and trot out the words of the greatest mind in the history of computer science (sorry, Turing and von Neumann fans).


2003-03-21 01:56:41
I'm sorry but that quote does not explicitly say that using indentation instead of delimiters is a good thing, nor do I believe that it implies it. What it seems to imply to me is that having the possibility of using indentation instead of delimiters is a good thing, not that indentation is in itself superior.

As for me I dislike indentation because it can make some forms of program generation more arduous, and searching in a text editor for the delimiting character can be easier than searching for whitespace. This does not mean that I find python to be a poor language for its usage of significant whitespace, it just makes it unlikely that I would use it.

2003-03-26 19:18:19
Life is better without braces
The clarity and lack of time fooling with syntax decoration using languages like Haskell and Python is amazing. Coding standards usually have some indentation portion, because thats how people perceive the code. Avoid learning Haskell or Python -- languages using tokens like "{" to decorate lexical blocks will just annoy you with how much time you waste decorating things and scrolling around.

Braces that C, C++, Java, Ruby etc. have just obfuscate the code (as do tags used for things other than document markup -- the real drawback to RDF is the XML serialization seems too too hard for people to think around. The same problme occurss with XSLT -- a really cool language that obfuscates itself with syntax. )

2003-03-26 19:19:47
Life is better without braces
Doh! I Hope this form isn't posted to a python CGI. I got an HTTP error every time I posted.

2003-03-28 13:55:41
Life is better without braces
The error has been fixed and I've cleaned up the duplicate post.

O'Reilly Network

2003-07-05 16:43:20
What's seriously amiss with Java?
Could the author please comment?
I think Java (particularly the new 1.5
coming out) is a pretty decent prog lang.

What don't you like about it?


2003-08-04 09:51:16
What's seriously amiss with Java?
The list is very wrong. My short answer is a quote of something I head a few years ago that sounded perfectly spot on:

"Programming in Java is like programming in a straitjacket"

Of course, YMMV, but in my experience, the amount of boilerplate and language magic one has to learn in order just to print "Hello World" is astounding

Java removes all tools that can be used for generic programming: including multiple inhertance and pointers, and replaces them with extremely weak tools: introspection that sits on top of the type system, etc. the result is that you have to use the modes of expression sanctioned by Java language designers rather than the most natural modes of expression for your problem.

(Java 1.5 addresses some of this, but in a very bolted-on manner that attempts to spot-treat particular areas where this inflexibility is a wel-known problem, rather than fixing the inflexibility systematically)

I find almost any other language out there more expressive than Java, incluidng C++ (and from what I've seen C#, which, however, is but a marginal improvement).


2003-08-04 09:55:31
What's seriously amiss with Java?
Oops. Should say "The list [of things amiss with Java] is very long."