Some normative recommendations for high-performance code

Source: Internet
Author: User

This is a good reference for some writing engineering, summary sharing under.

Database-related recommendations

1. The table design must contain 3 fields, a primary key ID field, an indexed gmt_ctreate field, a gmt_modified field that can be updated on the table and recorded at the same time

2. The field is non-negative, you must use the unsigned number unsigned

3. Disable database reserved words, such as Desc,match, because the late renaming of fields is costly

4. It is not recommended to index a varchar field unless the specified length

5. In,like operation should be avoided, the former need to evaluate the number of in after the set, the proposed control 10^3 within the efficiency of the like field whether the full table scan, the foreground is disabled, fuzzy matching as far as possible to determine the positive conditions, which can reduce a lot of data scanning.

6. The database avoids null values as much as possible

Code-related recommendations

1. Interface, not public in the method, try not to place the variable

2. Methods named using Camel, variable name to see the name of the meaning, the constant variable capital

3. The definition of the constant location of the absolute maximum access interval, such as the definition of the class is limited to the use of this class, a separate build package, up to this application-level access, multi-application access to third-party ant applications, such as Maven

4. Initialize variables to initialize common values as much as possible

5. ToString method, incidentally print the parent class ToString, if the exception information needs to print, try to print out the corresponding parameter name and value (called Field protection) +e.getmessage ();

6. The number of rows in the class is controlled within 100 lines for easy testing and readability.

7. The method returns the base data type as much as possible, thus avoiding the overhead of heap instantiation.

8. Foreach is the enhanced for loop, the collection class tries to avoid the remove operation and can use the iterator iterator method

9. The parameter check passed in the method needs to evaluate the frequency of the method call in advance, the frequency is high, before the parameter checking placement method call, of course, you need to write the method at the time of the parameter detection comment to prompt the caller. Ps:dao layer of the database to persist the method does not need to detect, call more frequently, check is generally placed on the service layer. Of course, for security, usability, RPC calls need to be checked in a higher method.

Recommendations for configuration

1. At present, the Java framework technology increasingly Peng Fei, later maintenance of the original project more see, the initial configuration should take into account the future problems. For example, the name of the service,dao,sql.xml (variable = attribute, method name = database operation name) is kept as consistent as possible.

2. The dependent jar package configuration follows the FIFO principle, to which the add-on should be added at the end. Tools such as Maven are analyzed from top to bottom for XML configuration

Some normative recommendations for high-performance code

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.