Config File Languages

Joe Marshall over at Abstract Heresies has a short allegory on designing configuration file languages. We’ve probably all been there. It starts off simple: he just wants a configuration file that handles key/value pairs. But then he finds he needs a bit more flexibility—Marshall’s example is getting a value from an environment variable—so his key/value scheme added an escape sequence to deal with this case. In the way of entropy everywhere, it just goes on and on.

Pretty soon, he realizes that what’s really going on is that he’s designing a crappy configuration language on the fly rather than designing a good one from the outset. As I said, we’ve all been there.

His last paragraph sums up the point:

If we had some forethought, we would have realized that we were designing a language and we would have put the effort into making it a good one. If we’re lazy, we’d just pick an existing good language. Like Lisp.

That brings us to Emacs. The Emacs configuration file is written in the same language that most of the rest of Emacs is: Elisp. That means that the configuration can be as rich as desired, including even adding or rewriting entire functions. That’s the real secret to Emacs’s famous extensibility: You can add to the core body of code right in the configuration file.

Sadly, not every application has the advantage of being written in a Lisp dialect but you can still leverage the advantages of Lisp by using Lisp for the configuration file. A great example of this is Guile, a Scheme-based extension language that can be linked into applications written in another language.

With a little planning, you can avoid the descent into despair of Marshall’s apocryphal developer.

UPDATE [2023-07-28 Fri 15:25]: Added link to Marshall’s post.

This entry was posted in General and tagged , . Bookmark the permalink.