My personal opinions on "Zero Configuration" and "configuration available" in program development

Source: Internet
Author: User

I am a Java developer and often use OpenSource open-source frameworks in program development. Most of these frameworks are flexible, simple, easy to use and convenient. In addition, the open-source framework generally provides some basic configurations. For example, we usually use Hibernate to configure object-to-database ing; spring needs to configure bean management, object and attribute injection, Struts needs to configure the Action object and the returned resource path, and MyBatis needs to configure CRUD (add, delete, modify, query) related SQL statements. You cannot omit these configurations. They must be available and will not be automatically added without programs. We are also very likely to simplify these configurations, but they cannot be omitted, although these frameworks provide great convenience for our development programs.

But sometimes you have a question: is it configured in XML? Or is it configured with Annotation? Or is the configuration mixed with XML and Annotation?

First, let's take a look at the advantages and disadvantages of the two configurations.

XML is an irreplaceable hypertext markup language with good readability and transmission. It also has the following advantages:
1. good readability and transmission: XML eXtensible Markup Language. The biggest advantage is that developers can customize the applicable markup for the software, greatly improving the code readability.
2. Flexibility, ease of use, scalability, and Portability: XML configuration can make the software more scalable. For example, Spring configures dependencies between classes in XML to maximize application scalability. Similarly, if it is based on the Interface injection method, you can switch the interface implementation class to perform the injection.
3. Verification Mechanism: it has a mature verification mechanism to ensure the correctness of the program. The Schema or DTD can be used to verify the correctness of the XML to avoid application errors caused by Invalid configurations.
4. modify the configuration without changing the existing program or re-compiling.

Although XML has so many advantages, it is not omnipotent. XML also has its own disadvantages:
1. friendly support for development: Support for parsing tools or class libraries is required. If your XML configuration requires XML prompts or parsing and compilation, you need to use Schema or DTD for verification.
2. Performance impact: parsing XML will inevitably affect application performance and occupy system resources. At least you will use some XML parsing techniques to parse the content of node elements.
3. high maintainability: too many configuration files make management difficult.
4. the correctness of the configuration item cannot be verified during the compilation period, or an error must be found at the runtime. For example, Spring Bean configures an incorrect class path.
5. IDE cannot verify the correctness of configuration items. For example, Spring injects an incorrect object or attribute.
6. troubleshooting becomes difficult. A wrong hand is often configured to cause inexplicable errors.
7. Developers have to maintain code and configuration files at the same time, resulting in low development efficiency.
8. A potential rule exists between the configuration item and the code, and changes to either side may affect the other side.

 

Let's take a look at the advantages of Annotation.
1. Save it in the class file to reduce maintenance costs.
2. No tool support or resolution required.
3. The correctness can be verified during the compilation period, and the error is easy to check, although some errors can be seen only during the running period.
4. simple configuration to improve development efficiency.

Similarly, Annotation is not omnipotent, and it also has many shortcomings.
1. to modify the configuration items, You have to modify the Java file and recompile and package the application.
2. The configuration item is encoded in a Java file, with poor scalability and low portability.

 

So what kind of configuration is used? Here I will talk about my personal views:
1. during development, we use Annotation annotations, which not only saves the maintenance of XML configuration files to a certain extent, but also greatly improves the development efficiency and shortens the development cycle.
2. After development, the project function is complete. You can convert the Annotation configuration to XML configuration and disable Annotation. The reason for this is that if the project goes online, we need to modify the configuration of the relevant code and directly change the XML and properties configuration files. In this way, developers do not need to find the corresponding code to modify the source code, re-compile, package, and release. The xml configuration can be directly modified without re-compilation. You only need to restart your server.

If this is the case, the Annotation provided by the framework is used, and the XML configuration is also used. We have made full use of the technical applications provided by the open-source framework.

3. hybrid mode. Annotation and XML are applied to each other. XML configuration is required for dynamic configuration and regular modification later. Annotation is used if not modified. Maybe this hybrid mode is more suitable for us, what do you think? O (distinct _ distinct) O ~

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.