Chad Perrin: SOB

28 May 2006

Whitespace and Instructional Programming Languages

Filed under: Cognition,Geek,RPG,Writing — apotheon @ 09:26

A discussion of the “whitespace problem” of Python occurred in another venue, and some of what was said there got me thinking. It starts with a complaint about the way Python eschews punctuation, and snowballs from there.

One particular point that came up was the assertion by Pythonistas that using significant whitespace instead of punctuation somehow reduces “syntactic clutter”, even while noting that whitespace is a part of Python syntax. It’s kind of surprising, once one stops to think about it, that these guys don’t notice that it doesn’t reduce “syntactic clutter” at all, but merely replaces one type of “syntactic clutter” with another. Depending on one’s definition of “clutter”, one might even say that Python’s approach increases rather than decreases “syntactic clutter”.

The comment that got me thinking the most interesting thoughts, though, was the one that mentioned a study that found significant whitespace provided an appearance that was “easier to read” for non-programmers than programming punctuation. I rather suspect that was skewed somewhat in favor of the significant whitespace crowd by comparing all-indentation-without-punctuation to all-punctuation-without-indentation. Of course, in the real world, nobody eschews indentation formatting in production code. It’s Just Not Done. I guess part of my problem with Python, based on that, is the fact that Python does something akin to making a law forcing people to use verbs. Everybody uses them already, and even if someone decided to avoid using verbs for some reason, it would surely be a joke that didn’t hurt rather than because they’re criminal masterminds. It’s the same situation with indentation in programming.

That note about non-programmers being better able to read it brings Ruby to mind (for me, at least).

Basically, the idea is that an instructional language has to be more than merely readable to someone that hasn’t yet been instructed. It also has to be writable and, perhaps most importantly of all, editable and debuggable. Python achieves the first of these, but demands an awful lot from rank newbies for the second (writing), and even more for the third (editing and debugging). Even expert Python programmers can have intractable issues with misplaced whitespace from time to time: I’ve heard the complaints. I’m inclined to try to insulate brand new programmers against the problem of spending an hour looking for one misplaced space in an indentation. Beginners should be learning how to develop good code, after all.

Good indentation formatting is important, but so too is everything else. A language that encourages good indentation is what’s really needed: making whitespace significant so that good indentation is necessary for the program to run is a very heavy-handed way to achieve that effect. Considering the wide range of languages available, and all the available syntactic quirks in all those languages, it seems something with a flexible syntax is more important than one that enforces a specific individual’s idea of what constitutes “good practice” — but there’s no reason to pick a language with a flexible syntax that doesn’t encourage “good practice”. In addition, anything you can do to increase the ability of a new programmer to recognize what’s going on is a good thing: eschewing end delimiters just because you think you’ve found the Holy Grail of indentation schemes and enforced it syntactically seems antithetical to that aim.

Ruby seems to provide all of these benefits, and also makes a smooth path of transition toward learning the formatting methodologies employed by other languages. What’s not to love?

That’s how I see it, anyway.

All original content Copyright Chad Perrin: Distributed under the terms of the Open Works License