Settings.yaml

By peter, 25 March, 2025

Settings files contain things software needs when starting up. Yaml is one of hundreds of formats used throughout computing systems with advantages and real problems. Here are things to think about based on real life experience.

Who?

Settings files are used by software and may be designed so you can edit them before you use the software. If you are not supposed to edit them, they might be designed to let you read them when you have to diagnose problems. A good settings file is often called "human readable" even when the settings are meaningless. They may use text instead of binary code but the text may not mean anything useful.

Yaml is a format designed for programmers using the Python language and follows the weirdly structured Python code format. The result is a text file hard to read if you are not a Python programmer and incredibly dangerous to edit.

When?

Settings files always make sense for software applications as you can change default values and configurations without understanding the code or recompiling or anything complicated. The settings available to you should be be safe, not dangerous, and carefully checked by the software.

Yaml format files are complicated to understand and dangerous to edit. Only Python programmers use that weird layout, that difficult indentation, and the completely unreliable dependency on whitespace meaning something other than whitespace. Yaml should not be used outside of Python and then should only be used for files created by and for programmers.

Why?

Human readable files are text based. The text contains many files that are whitespace and not displayed. Yaml structures settings using whitespace. Whitespace includes many characters. Editors show all whitespace as a space or multiple spaces. Yaml ignores the second most popular whitespace character.

The result? Yaml depends completely on indentation and the indentation looks perfect but Yaml ignores part of the indentation without any way of you understanding the error. You then have to find a special editor that displays each whitespace character as a not-whitespace character then change the whitespace characters Yaml does not like to s character it likes.

After hours of pain, Yaml starts to look like a really stupid choice. Except, perhaps, to someone who suffered through learning Python.

If you output a settings file in code then read it back in and do not let users edit the file, Yaml can work as there are ready made code blocks to create a Yaml file then read it back. The modern approach is to use JSON instead of Yaml when only software processes the file.

Way?

There is, for every programming language, a software package to create then read standard formats including JSON, XML, and Yaml. You can force users to make settings changes only through your settings interface. Behind that, you can use any file format. The format does not matter.

When something breaks, XML can be a pain to read. Yaml and JSON can be easier to read so long as you use an editor with a consistent display of whitespace.

After you find the cause of the problem, editing the settings file to fix the problem is difficult. Whatever you do, never use tabs. If you can change your editor settings, make it output a tab as a single space. The file might then work in Yaml.

Worth?

Yaml is worthwhile for Python programmers. For everyone else, it is a pain. The pain is reduced if you can switch off tabs when editing Yaml files or you can tell your editor software to replace tabs with spaces for all .yaml files.

Comments