YAML, JSON, ini, and XML are used to make configuration files. What are the advantages and disadvantages? Followers

If our program does not have any configuration files, such a program is completely closed to the outside world. Once the program needs to modify some parameters, the program code itself must be modified and recompiled. This is not good, so we must use configuration files to let the program leave the factory. You can also perform necessary configurations as needed; the configuration file is mainly used to store key-value pairs, which is similar to a map. Therefore, it is not a bad idea to design a simple configuration file format yourself. Just because there are already a large number of mature configuration file formats available, just use the existing ones.

There are many configuration files, such as INI configuration files, XML configuration files, YAML, JSON, and you can also use the system registry, etc. Each of these configuration files has its advantages and disadvantages, mainly in two aspects:

Expression ability
refers to the richness of the data format that this configuration file can express, such as whether a complex data structure can be expressed.

xml > yaml > toml > json > plist > ini

Human readability
refers to whether the content of this configuration file can be easily understood when opened directly with a plain text editor such as Notepad.

ini > toml > yaml > json > xml > plist

Summarize

In general simple situations, the ini configuration file is actually enough (it is more classic, used by many people, and is most common in Windows systems), supports the use of the most basic key-value pairs, and is very readable. Annotations are also supported. The parsing speed is also fast. There are open source libraries available (since the file format is really simple, it's also quick to write a few simple parsing functions yourself). Of course, the file extension does not necessarily have to be ini, but other things are also fine, because the analysis function can parse its content.

simpleini/README.md at master · brofield/simpleini · GitHub

simpleIni library for parsing ini files in c++

Of course, for complex data structures, json is enough (many people use it, for example, the configuration file of vscode is this). Various programming languages ​​have mature open source libraries. This is a configuration file that balances expressiveness and readability, but it does not support comments. Note in particular that the comments in the ini file must start on a single line (not on the same line as the data), start with a semicolon, ;xxxxx. If it is in the same line as the data, an error will be reported: Version of file xx is no longer supported.

If you have higher requirements, choose a configuration file with stronger expressiveness, but the readability and parsing speed will be poor.

Therefore, I generally use ini and json more.

Reference article:

YAML, JSON, ini, and XML are used to make configuration files. What are the advantages and disadvantages? - Know almost

.ini file—configuration file_fpn233’s blog-CSDN blog_ini configuration file
————————————————
Copyright statement: This article is the original work of the CSDN blogger “I am a classmate” This article follows the CC 4.0 BY-SA copyright agreement. Please attach a link to the original source and this statement when reprinting.
Original link: https://blog.csdn.net/kangkanglhb88008/article/details/125854265

Suitable for humans to write: ini > toml > yaml > json > xml > plist

The complexity of data that can be stored: xml > yaml > toml ~ json ~ plist > ini

Guess you like

Origin blog.csdn.net/u012294613/article/details/132316026