2006-10-30
A brief Exim observation
Life probably would be easier if the people behind Exim's string expansions had just been able to write a Lisp. Unfortunately that might have created some irrational prejudice against Exim, so I can see why they needed to disguise what they were doing.
(It would have been a pretty mutant Lisp. But mutating your Lisp is almost de rigueur.)
Of course, I must include a pointer to Greenspun's Tenth Rule of Programming.
2006-10-26
Languages need comments
Through various experiences, I have come to a modest conclusion about designing languages:
Every language, be it ever so tiny, needs to have a way of including comments.
And I do mean every language. Even things that are barely programming languages, like configuration files and dinky templating systems, need comments. Sometimes I think that these tiny languages especially need comments; because they are so small and constrained, the tricks you do are likely to be even more obscure and hard to follow.
Yes, this means that I'm falling down on the job with DWiki's template syntax. The real irony of this is that I've had a syntax for comments picked out for some time and adding it to the code is totally trivial, but I just haven't gotten around to doing it. Partly it's because I don't have much enthusiasm for adding comments to the current templates, so I'd either be adding something I won't use or something that will make me feel guilty about undone work.
In theory templating systems that produce HTML can just include HTML comments, but that winds up with the HTML pages that are served to users having all sorts of peculiar internal annotations in them. I am kind of fussy about serving neat, nicely formatted HTML to visitors, even if it's automatically generated, so this makes me cringe. (Some people will also consider it a security hazard, but I'm not that paranoid.)
2006-10-13
Why quoting in the Bourne shell makes me grumpy
Imagine for a moment that you have an almost arbitrary string (no nulls, newlines, or other funky control characters) that you want to quote so that it passes through the Bourne shell intact. How do you do it?
The Bourne shell offers you two quoting schemes, strings in single quotes and strings in double quotes.
Strings in double quotes need special characters escaped with backslashes. There are five of them (quick, do you know them all?), or six in some situations in some versions of the Bash manpage. And of course, backslash is not a general escaping character; putting it in front of a non-special character is not harmless.
Strings in single quotes can't have anything escaped, which is OK, because nothing has special meaning inside them. Except a single quote. Since there is no way of escaping the single quote, you get to turn a single quote into five characters:
'"'"'
(Okay, I suppose you could turn it into '\'' instead and save yourself
one character, at the expense of generating something that looks even
more like you stuttered.)
(You may or may not be able to read that in your font, since a fair number of fonts are not so great at distinguishing single quotes, double quotes, and apostrophes. It's almost as bad as the great l vs 1 problem.)
This leads to a general view of mine: often, the more quoting methods you have the worse off you are. Unless they are very specialized, quantity serves mostly to confuse, annoy, and surprise; you are better off with one method, ideally one as simple as possible.
Sidebar: so how should shells do quoting?
I'm glad you asked. Tom Duff's rc answered this question many years ago:
A quoted word is a sequence of characters surrounded by single quotes (
'). A single quote is represented in a quoted word by a pair of quotes ('').
That's it. As a bonus it's dirt simple to write code that quotes a string for rc: double any single quotes, then put the whole thing in single quotes.