autoconf: Changequote is Evil

1 
1 8.1.5 `changequote' is Evil
1 ---------------------------
1 
1 The temptation is often high to bypass proper quotation, in particular
1 when it's late at night.  Then, many experienced Autoconf hackers
1 finally surrender to the dark side of the force and use the ultimate
1 weapon: `changequote'.
1 
1    The M4 builtin `changequote' belongs to a set of primitives that
1 allow one to adjust the syntax of the language to adjust it to one's
1 needs.  For instance, by default M4 uses ``' and `'' as quotes, but in
1 the context of shell programming (and actually of most programming
1 languages), that's about the worst choice one can make: because of
1 strings and back-quoted expressions in shell code (such as `'this'' and
1 ``that`'), and because of literal characters in usual programming
1 languages (as in `'0''), there are many unbalanced ``' and `''.  Proper
1 M4 quotation then becomes a nightmare, if not impossible.  In order to
1 make M4 useful in such a context, its designers have equipped it with
1 `changequote', which makes it possible to choose another pair of
1 quotes.  M4sugar, M4sh, Autoconf, and Autotest all have chosen to use
1 `[' and `]'.  Not especially because they are unlikely characters, but
1 _because they are characters unlikely to be unbalanced_.
1 
1    There are other magic primitives, such as `changecom' to specify
1 what syntactic forms are comments (it is common to see `changecom(<!--,
1 -->)' when M4 is used to produce HTML pages), `changeword' and
1 `changesyntax' to change other syntactic details (such as the character
1 to denote the Nth argument, `$' by default, the parentheses around
1 arguments, etc.).
1 
1    These primitives are really meant to make M4 more useful for specific
1 domains: they should be considered like command line options:
1 `--quotes', `--comments', `--words', and `--syntax'.  Nevertheless,
1 they are implemented as M4 builtins, as it makes M4 libraries self
1 contained (no need for additional options).
1 
1    There lies the problem...
1 
1 
1    The problem is that it is then tempting to use them in the middle of
1 an M4 script, as opposed to its initialization.  This, if not carefully
1 thought out, can lead to disastrous effects: _you are changing the
1 language in the middle of the execution_.  Changing and restoring the
1 syntax is often not enough: if you happened to invoke macros in between,
1 these macros are lost, as the current syntax is probably not the one
1 they were implemented with.
1