Zachary Kanfer
I write about programming, music, and comedy.
3y ago
Config files are the worst code.
Zachary Kanfer

Config files should be as readable as code.

There's a lot of discussion about how to make code readable, but rarely about how to make configuration files more readable. Programmers focus on code because that's the more exciting part of solving problems -- code is dynamic and powerful. Configuration files don't process data; they are data!

But this leads to configuration files being hard to read.

  • Grouping of similar attributes is often ignored. The language doesn't encourage good organization the way programming languages do.

  • Rarely is there explanation of what a setting does, or why it's configured that way. Sometimes the configuration language doesn't have comments, so there can't be this added explanation!

  • Many configuration languages aren't Turing complete, and are painfully limited, without variables, loops, or functions.

  • Setting names are often painfully abbreviated or obtuse.

  • Tooling around config files is far more limited than code. "show usages" commands are common for functions and classes, but not for config values. It's hard to clean up configs without knowing what is unused.

Config files change how the whole program runs, so they're just as important as code.

And if config files are that important, it's vital they be readable.

What good is a config file if it's unreadable? The program using it might work for the moment, but it will quickly become unmanageable. Software that is difficult to read is quickly fixed. Config files should be treated the same way.

And it's not especially hard.

You have to care.

Treat your config files the same way you do your code. Think about someone unfamiliar with the config reading it for the first time. Will they have the proper context to understand?

One way to improve config files is to order the lines to group similar attributes together.

Your configs will be more readable. When you come back to a project, you'll be able to quickly understand whether two values are related, because you left a comment. You'll see all related settings in a single block, and know how the software will run.

This will make your software more reliable.

0

Atomic Essay

Comments

What will you write today?

Write, publish, get feedback, and become a better writer.

Trusted by 75,000+ writers