0

Backstory

I am building a daemon that is to be run in the background on systems based on X11. As of right now, the settings are hardcoded, and that obviously needs to change. As such, I plan to create a /home/user/.mydaemonrc

Issue

Different run configuration files tend to have different syntaxes.

.vimrc for example is completely different than .zshrc, and it is not clear to me how or why they chose their respective syntax.

Questions

  1. Any obvious way forward when choosing what syntax a run configuration will use?

  2. Do any commonly used tools (Classes maybe) exist for designing and parsing configuration files?

  3. Is making the Run Configuration File an xml a good idea?

  4. Anything else worth considering?

Thanks.

2
  • 1
    To make a choice like this, you have to know what your goals are, and which approach best meets those goals. From my perspective, I've never heard of .vimrc or .zshrc, but I have heard of XML and used it to good effect. Perhaps the Java folks know what these files are, but one of your goals might be familiarity and ubiquity, and most software developers who have been around longer than a week know what XML is and how to use it. Commented Jul 29, 2017 at 16:13
  • Related, possible duplicate: softwareengineering.stackexchange.com/questions/351126/…
    – 8bittree
    Commented Aug 1, 2017 at 22:07

1 Answer 1

1

TL;DR

If your program does not already implement or integrate a scripting language, use a standardized format like TOML, YAML, JSON, or XML. In this case, I would include to appropriate file extension, just to make clear that it is, indeed, that format, and not just something superficially similar.

If your program does implement or integrate a scripting language and it's one the typical user will be exposed to frequently enough to gain familiarity during typical usage of your app, consider just using that language.


Vim and Zsh are both interpreters. Vim implements the Vim Scripting Language (sometimes called Vimscript or VimL):

The Vim script language is used for the startup vimrc file, syntax files, and many other things.

Zsh implements, um, Zsh, which is also a programming language:

Zsh is a shell designed for interactive use, although it is also a powerful scripting language.

(Emphasis added by me)

The Vim quote outright says it, vimrc is written in VimL. The same applies to zshrc: it's written in Zsh. Additionally, whenever you use a command in command-line-mode in Vim or write a command at Zsh's shell prompt in the terminal, you're writing VimL or the Zsh language, respectively.

What this all boils down to is that the authors of Vim and Zsh didn't invent some new, unique syntax for their config files, they just reused the programming languages their programs already implemented. Since their users use these languages to interact with the programs, the users can easily become quite familiar with them, making it easy to understand the config files.

This is especially true for Zsh, where, aside from some control-codes, and minor cursor manipulation, the only way to interact with the shell is through the language. It's somewhat less true for Vim, where most of the interaction may happen through normal and insert mode, and even the number of commonly used command-line commands may be limited.

Not the answer you're looking for? Browse other questions tagged or ask your own question.