Active whitespace is evil

From Pirates@Home

Jump to: navigation, search

More and more I come up against cases where whitespace can have an operational effect on how a software system works, and in most cases this can lead to serious problems, or at least frustrating problems that are difficult to diagnose, because they are caused by what we usually ignore -- whitespace. Whitespace is most often spaces or tabs, but could also be vertical tabs, line feeds, form feeds, or even just indentation. This page is a place for me to collect all the examples of active whitespace, and to list those uses which are evil and those few that are not.

Contents

Evil

  • Tabs in Makefiles: In a Unix Makefile the syntax is that you begin a build rule with "target: list-of-dependencies", and then the following lines that begin with tab are the commands that are executed to build the target from the dependencies. But if one of those lines does not begin with a tab then it isn't exectued and that is the end of the rule. Finding an error like this is maddening.

(The Emacs editor will check syntax on a Makefile, but you should not have to rely on some other program to save your bacon.)

  • Indentation in Python: In the Python programming language indentation sets the scope of local variables the way curly brackets do in C-style languages.
  • wiki line breaks: If you write text for a paragraph in Twiki it gets run all together, even if you put in hard line breaks. But if you turn that paragraph into an item in a list (by beginning the line with three spaces followed by *) then the hard line break ends the item. Ugh.

And MediaWiki seems to do the same thing, as you can see from this line.

  • Twiki list markup: Twiki requires list items begin with exactly 3 spaces per level of indentation. Which makes it very fun (NOT!) when using a proportionally spaced font, as you can't just line things up to see that you have the requisite number of spaces. Dumb choice of markup convention.

Somewhat Evil

  • White space at begining of line in MediaWiki: if you begin a line of text in MediaWiki with a space then that text is set off from the rest of the text as if it is computer code. Here is an example:
the problem is, it's a common thing to do

and it's very confusing if you don't know that the space at the beginning of the line is the cause. (It's actually very useful once you know what is happening, so this is only slightly evil.)

  • Unix -vs- MS DOS line endings: The problem is not that whitespace characters are used as line endings. Each makes some sense, at least historically. The problem is that there are two different conventions and you have to convert between them. That's mildly evil.

Not evil

  • In TeX, as well as in MediaWiki and other wiki markup a blank line begins a new paragraph. That's an active function of whitespace, but in this case it's not evil. After all, when you just type text, a blank line can be used to separate paragraphs. So in this case the active whitespace is functioning as it should.

Amusing

  • In the computer programming language called Whitespace, whitespaces are the only valid characters for programming, while any other characters are ignored. This is an amusing way to demonstrate active whitespace taken to an absurd extreme. And it provides a way to embed secret messages in other programs, via steganography.
Personal tools