Slightly larger software will require a configuration file to support software execution. The common configuration file format is plain text right now. XML. SQLite. How do I choose my own binary format?
1 Plain Text-file formats that will never expire
The text is one of the dogmas of the traditional Unix philosophy, which shows its great power. The software configuration files for most Unix-like systems are in plain text format.
such as/etc/inittab,/etc/fstab, httpd.conf and so on.
1.1 Advantages
(1) Strong readability
Configuration files need to be understood not only by machines, but also by people.
Plain text is easy to understand.
(2) There are a lot of plain text editing tools
Able to use whatever editor changes.
Do not underestimate this strength, its impact is huge. There are a lot of very useful search for plain text, editing tools (such as Grep,sed,awk), think of the normal form, you know why the plain text is so important.
(3) can be permanently saved
In the past few decades. Various file formats abound. But think about it carefully. More than 10 years ago, the files that were left to be viewed and used today are really not much, and the plain text format is one of them.
No matter what the age. It's always easy. Find a text editor to view changes to plain text files.
(4) Cross-platform
Character encoding spans no matter what computer platform. What 32-bit system, 64-bit system. What Linux,windows,mac,ios, Android, treats plain text in a way that is consistent.
1.2 Disadvantages
(1) parsing cumbersome, no ready-made library available
Different configuration files often define their own detailed implementation format. This requires a custom parsing code. A slightly more complex configuration file often leads to cumbersome parsing code.
(2) Clear text is not safe
Some of the program's configuration files are also part of intellectual property and need to be concealed.
Plain text does not have this functionality.
2 xml--of the internet age
With the wind of the Internet. XML is large in its way. Many large software starts with a configuration file in XML format, such as Tomcat.
2.1 Advantages
(1) All the advantages of plain text
XML itself is also plain text, only on the basis of plain text. A unified document structure layout is defined.
So, the advantages of plain text, XML also have. No longer described.
(2) Especially suitable for tree-level data storage
Many of the model data are tree-like. XML itself is designed for tree-like data.
(3) Unified layout, ready-made analytic library available
Almost all languages now have libraries available that support XML parsing. This eliminates the parsing code, not easy error.
2.2 Disadvantages
(1) Meta data is repeated. Wasted Space
XML configuration files tend to be larger than plain text, and look at the large number of configuration files under Tomcat.
(2) readability, editable than plain text
XML facilitates machine identification and analysis. But not very suitable for people to read. In particular, the structure of complex XML documents.
(3) need the main DOM Foundation, the ability to use
Not all program apes have a DOM base, so there's a certain threshold for entry
3 sqlite--Best Single-file database
The famous CentOS package management system Yum's library manages data using SQLite.
3.1 Advantages
(1) There is only one file. including everything
This advantage is very obvious. SQLite requires only one file to include all configuration data, which is good for backup and recovery.
(2) Support SQL query Language
This is the biggest advantage of SQLite, the program apes do not care about the detailed I/O, just use SQL to be able to manipulate the data.
(3) The amount of data can be very large
The instant profile size is at the GB level, and SQLite still performs well and consumes little memory.
(4) Open source code
SQLite source code uses the most lenient authorization – no authorization required.
The ability to use its source files directly in the project.
(5) The SQLite library is stable
SQLite has undergone more than 10 years of development. has been very stable.
(6) Can add change configuration item at any time. Without changing the usage code
This is also a huge advantage of the SQL language
(7) Cross-platform
Across different architectures. Different operating systems.
3.2 Disadvantages
(1) cannot be viewed with a text editor
Although the current SQLite software is very popular, but after all, it is dedicated software, as a text editor, everyone will use. and years later. No one can guarantee that SQLite will continue to develop well.
(2) Require users to master the SQL language
Not all of the program apes are familiar with SQL.
(3) because it is working on the hard disk data, so small files. Slower than XML.
For the profile, this is not a problem, after all, most of the configuration files are only used when the program starts.
4 self-defined binaries-obsolete garbage
The configuration file in which you define the binary file format is not advocated today. The apes are still in use on extremely special occasions and some ignorant programs.
Like what. Systemd Another part of the configuration file is such a binary format, but under pressure from all sides, slowly also in the way of the plain text evolution.
What is the
configuration file format used for? Folder + Plain text file, Xml,sqlite