Code configuration vs. Configuration File

Source: Internet
Author: User

Code Configure. configuration File
another issue is relatively independent, but it is often associated with other issues: how to configure service Assembly through the configuration file
is it a direct code assembly? For most applications that need to be deployed in multiple places Program , a separate configuration file is more suitable.
configuration files are almost all XML files, and XML is indeed suitable for this purpose. However, sometimes it is easier to
implement the Assembly directly in the program code. For example, there are not many changes in the deployment of a simple application, and the configuration is much clearer than the XML file by using a few pieces of code.
In contrast, sometimes application assembly is very complex and involves a large number of conditional steps. Once the configuration logic in programming language
becomes complex, you should describe the configuration information in a proper language, make the program logic clearer. Then, you
can compile a constructor (builder) class to complete the assembly. If there are more than one constructor scenario, you can
provide multiple constructor classes and select between them through a simple configuration file.
I often find that people are too eager to define configuration files. Programming Languages generally provide simple and powerful configuration management mechanisms. Modern
programming languages can also compile programs into small modules and insert them into large systems. If the compilation process is laborious, the script
language can also help in this aspect.
generally, configuration files should not be written in programming languages because they must be compiled by system administrators who do not understand programming.
. However, what is the probability of such a situation? Do we really want programmers who do not know how to change the transaction isolation level of a complex
server-side application? Only when it is very simple, non-Programming Language configuration files have the best effect
. If the configuration information becomes complex, you should consider selecting a proper programming language to compile the configuration file.
in the Java World, we have heard the discord from the configuration file-each component has its own configuration file, and
the format is different. If you want to use a dozen of such components, You have to maintain a dozen of configuration files, which will soon upset you
.

here, my suggestion is: always provide a standard configuration method that allows programmers to easily complete configuration through the same programming interface
. Other configuration files only use them as an optional feature. With this programming interface, the
publisher can easily manage configuration files. If you have compiled a component, the component user can choose how to manage it
Configuration Information: Use your programming interface to directly operate the configuration file format, or define their own configuration file format and
combine it with your programming interface.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.