It doesn't have much of a syntax aside from where you place the data in relation to previous data. YAML is popular partly because it looks clean. YAML files are structured lists that can contain values or key and value pairs:. However, it's a popular enough format that most languages have an existing library to help programmers parse INI files. When parsing such a file, a developer must be careful to search within sections for keys, which can be tricky depending on the language used to parse the file. You can imagine a careless programmer querying this config file for name and always getting back Beastie because that's the last name defined by the file. This is a little more complex to parse because there are two name keys. In this sample code, and are configuration sections: The INI format features sections in addition to keys and values. This simple style of configuration can be intuitive, with the only point of confusion being poor key names (for example, cryptic names like unampref instead of name). INI files take the format of key and value pairs: There are several popular formats for configuration files, each with its own strengths. The last thing you want to do is dump information into a file under the auspices of saving user preferences and then spend days writing code to reverse-engineer the random bits of information that have ended up in the file. To be broadly effective, the most important thing about configuration files is that they are consistent and predictable. As long as you have a consistent data structure, you can write simple code to extract and parse it when necessary. The same principle applies to any programming language and any configuration file. Here are two simple examples, one using the awk command and the other using the grep command, focusing on just the line containing the "key" of NAME, and returning the "value" appearing after the equal sign ( =): $ awk -F'=' '/NAME/ ' myconfig.ini Usually, though, an application needs to keep track of more than just one piece of information, so configuration often uses a key and a value: NAME='Tux'Įven without programming experience, you can imagine how code parses that data. For instance, if you were to write an application, and the only thing it ever needed to know was its user's preferred name, then its one and only config file could contain exactly one word: the name of the user. It's thanks to config files that any time you launch an application, it has "memories" of how you like to use it.Ĭonfiguration files can be, and often are, very simple in structure. They allow you to customize how you interact with an application or how an application interacts with the rest of your system. Why we need configurationĬonfiguration files ("config files" for short) are important to modern computing. However, the tech industry graciously favors well-documented standardization, so several well-known formats have evolved over the years to make configuration easy. Storing configurations is a flexible task because as long as developers know how their code puts data into a file, they can easily write code to extract that data as needed. ![]()
0 Comments
Leave a Reply. |