Pseudocode and indentation
“In pseudocode we use indentation while in most languages they have begin, end delimiters. Curly braces or something like in Java or C for example. But we use indentation. The whole idea of pseudo code is to get the algorithms as short as possible, while still understanding what the individual steps are. In practice there’ve been languages that use indentation as means of showing the nesting of things. In general it’s a bad idea because when things move from one page to another for example you can’t tell what level of nesting it is. Whereas with explicit braces it is much easier to tell. So there are reasons why this is a bad notation when you are doing software engineering, but it’s a good one for us ’cause it keeps things short and thus fewer things to write down.”
By: professor Charles E. Leiserson in Analysis in Algorithms

November 17th, 2009 at 11:56 am
I haven’t watched the presentation and I just wanted to comment what you’ve written above (there seems to be a transcription error by the way, see [sic] below).
The only valid argument I’ve come across against using indentation to delimit blocks is that it can make refactoring your code a bit more difficult. But the argument Leiserson makes in this presentation, that it’s a bad idea because “when things [sic] from one page to another for example you can’t tell what level of nesting it is” makes no sense, what’s a “page” anyways?
I’ve been dabbling in Python over the last few years and I have never had a problem with the indentation, though I must admit that I haven’t done any truly intensive refactoring. Any language with braces nowadays just feels verbose to me.
November 17th, 2009 at 12:32 pm
Hi Bruce,
Thanks for your comment. I’ve edited the transcript and added the word ‘move’. As far as I remember that’s what he said in his lecture and this makes more sense
Regarding the “when things move from one page to another for example you can’t tell what level of nesting it is”, in the context of he lecture he refers to writing down algorithms in pseudo code and I presume his students are required to hand in algorithmic solutions written down on paper. Then a page makes sense
Actually, even if you’re using an editor like Vim or Emacs you’re limited to what you can see of the code due to the size of your screen, so when scrolling large pieces of code it still might make sense (although in my experience if a related block of code is longer than a screen scroll, you might want to divide it up into more manageable chunks, but that’s a different discussion) to use braces instead of indentation in languages where indentation is not part of the language such as Python.
As for why I quoted Leiserson: there’s tons of people writting php code without braces and using indentation instead. Since the php language does nothing to enforce indentations it can become quite ugly and very annoying code to maintain or extend. Especially with regards to ‘refactoring’ or just adding code to for instance if..elseif..else type of control structures. In the Wordpress community I’ve come across this misuse of indentation instead of braces on a daily basis and it’s a pain to work with. I would prefer people to apply the conventions of the languages they use. In Python this means indentation and in PHP it means using braces.