This article aims to tell the most boring basic knowledge in the most popular language

1

2

3

4

5

The above all kinds of funny naming problems.. I believe many partners will also encounter such, some because of lack of experience, some because they have not written code to do some standardized work, some because of old projects, predecessors brought out the bad habits… These are all very bad behavior in the programming world, not to be fully counted: programmers spend 80% of their time working with variables, functions, and methods on a project, so a good naming habit is more important than comments or a detailed development document. In view of this, xiaobian specially according to the industry standard – Ali development documents, made some references and excerpts, sorted out a specification on naming, to the need for your reference.

Try to write more beautiful code and less comments!!

Article outline:

  1. The overall specification
  2. Package specification
  3. Type of specification
  4. Methods the specification
  5. Some mandatory specifications for OOP

1. Overall specifications

  1. All names must be freely translated in English, not in pinyin. For example, to get myMessage interface, you can write: myMessage; But cannot write: myXiaoXi
  2. Try to use simple English names, but to express the meaning of the complete, avoid int a,int A1,int aa, such as meaningless simplification.
  3. All names cannot start with a special character, such as _age or _username
  4. Public final int REDIS_MAX_IDLE=5; public final int REDIS_MAX_IDLE=5;

2. The package specification

  1. Package names are all lowercase and cannot be written with special symbols or humps such as com.courselog.uitl_con.
  2. The package name should fit the purpose of the package, such as dao for data layer, util for toolkit, etc

3. The class specification

  1. A camel name that starts with an uppercase name, such as ApiController and TestController
  2. Exception class names end with Exception, such as CustomerException
  3. Abstract class names start with Abstract, such as AbstractCustomer
  4. A Test class name starts with the name of the class it is testing and ends with Test, for example, CustomerControllerTest
  5. Enumeration class names must end in Enum, if CustomerRoleEnum
  6. Other types of class naming, while describing the role of the class, also try to express some of the design patterns used by the class

4. Method specification

  1. Method names are written in camel case and start with a lowercase letter, for example, getUserCourse();
  2. Parameter names, member variables, and local variables in a method are all humped and start with a lowercase letter, for example, int userName.
  3. Do not add any modifiers to the methods and attributes of the interface class to keep the code simple.
  4. Method definitions must have comments, including (method action, parameter name, return type, creation time, etc.)
  5. Service/DAO layer method naming convention:
  1. Methods that get individual objects are prefixed with get.
  2. Methods that get multiple objects are prefixed with list.
  3. Methods that get statistics are prefixed with count.
  4. Insert methods are prefixed with save/insert.
  5. Delete methods are prefixed with remove/delete.
  6. The modified methods are prefixed with update.

5. Some mandatory specifications of OOP

  1. Avoid using variable parameters for programming. Java variable parameters can be used only when the parameter types and service meanings are the same, and Object is not used
  2. Obsolete interfaces must be annotated with @deprecated
  3. Do not use obsolete classes or methods
  4. The equals method is used to compare the values of all wrapper objects of the same type
  5. Methods within a class are defined in the order public or protected > private > getter/setter methods.

Find this article helpful? Please share with more people to pay attention to “programming without boundaries”, improve the installation force skills