Programming specification 1

Source: Internet
Author: User
Tags array definition constant definition uppercase character

Large manufacturers pay more attention to code specifications, especially scalability, maintainability, and readability. If you are a developer who just entered the company, you 'd better first ask your predecessors if they have

Internal Development specifications take some time. Even if there is no review step for submitting code, you should have a specification in mind. The industry is more unified here.

I. Naming Style

1. abstract classes start with abstract or base, exception classes end with exception, enumeration classes end with Enum, constant classes end with consts, and test classes end with test

2. In the array definition, the type is close to the braces int [] arr;

3. Do not add the is prefix to boolean variables in the pojo class.

4. The package name is in the singular form. If the class name has a plural meaning, it can be in the plural form, such as utils.

5. Do not abbreviated words unless they are recognized in the industry

6. If the design mode is used, it should end with the mode name, such as orderfactory and serviceproxy.

7. Do not add any modifier to the methods and attributes of the interface class. The methods earlier than 1.8 are all public abstract by default, and the attributes are all public static final.

1.8 and later, the static and default modifiers are added. Both methods require the method body.

8. interfaces and implementation classes: xxxservice, xxxserviceimpl, xxxdao, xxxdaoimpl

9. Method Name of the class with hierarchical structure:

(1) Get a single object and use get as the prefix GetObject

(2) obtain multiple objects and use list as the prefix + plural form to end listobjects

(3) obtain the statistical value and use count as the prefix.

(4) The insert method uses save/insert as the prefix.

(5) Delete the prefix with remove/delete

(6) modify the prefix with update

(7) Two VO types: data table object xxxdo and webpage view object xxxvo

Ii. Constant Definition

1. Long-type value assignment ends with an uppercase character l to avoid confusion between digit 1 and lowercase letter L.

2. Constant classes should also be classified. Do not put them all together. For example, cacheconsts is used for Cache-related constants and configconsts is used for system configuration,

These classes are all placed under the constant package, and internal constants of the class are used in this class. Do not publish them in the constant class.

3. Variable values change within a fixed range and are defined using the enum type. For example, the Chinese character escape of common database Field Values

Iii. Code Format

1. Braces. For example: (A space is left between the braces on the left and the characters)

int a(){};int a(){    System.out.println("1");}int a(int b){    if(b==1){        System.out.println("1");     }else if(b==2){        System.out.println("2");     }else{        System.out.println("3");     }  }        

2. Parentheses, left and right parentheses and no spaces are left. If/For/while and other Reserved Words and brackets with a space

3. Add a space between the left and right sides of the operator.

4. Use a unified tab indent and set it in advance on IDE and other development tools.

5. line feed: the operator and the point operator wrap the line together with the following. The line feed of the parameter is after a comma. The most common method is append ("XXX ").

6. Ide sets the text file encoding to UTF-8 in a unified manner. line breaks use Unix format instead of Windows format.

7. The total number of methods should not be too large. Generally, 80 rows are recommended. The additional logic should be extracted from an independent method to make the trunk logic clear.

8. In addition to logic or service meaning, an empty line is required to be separated. In other cases, do not create meaningless blank lines.

Finally, after writing intellij class, you must press CTRL + ALT + O, CTRL + ALT + L; after writing eclipse class, you must press Ctrl + Shift + F, otherwise, you must be conscientious.

 

Programming specification 1

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.