Home > Web Front-end > JS Tutorial > Questions and answers about camel case naming and JS

Questions and answers about camel case naming and JS

php中世界最好的语言
Release: 2017-12-04 14:57:49
Original
2500 people have browsed it

This time I will explain to you about camel case naming and how to use camel case naming in JS, as well as precautions before use. Let’s look at the detailed introduction below.

Notes before using camel case naming: 1. Due to the characteristics of Javaobject-orientedprogramming, when naming, you should try to choose nouns

when naming variables or functions. When one or more single words are connected together to form a unique identifying word, the first letter starts with lowercase and the first letter of each word is capitalized (except for the first word).

For example: myFirstName

Writing specifications for a package name (Package) It is recommended to use the top-level domain name of the company or organization as the prefix of the package name. The purpose is to ensure that the package used within each company/institution The uniqueness of the name. Package names are all lowercase letters and have practical distinguishing significance.

1.1 General requirements 1. Choose a meaningful name that can quickly convey the purpose of the class.

2. All package names must use lowercase English letters.

1.2 Practical application Layering is often used in application systems, including Dao layer (database access), Service layer (business processing), and Web layer (page control action class).

1. The first few names of the package name are fixed names. If it is a website, the domain name of the website is written in reverse. If the domain name has not been determined, the names fixed by the company are used. For example: net.vschool

2. The next word in the package name is the name of the module. For example: user module, the package name is net.vschool.user

3. Regarding the access operation of the module, it adopts a hierarchical form and is generally divided into:

Dao layer operation: generally defined in net .vschool.xxx.dao, where xxx is the module name.

Service layer operation: generally defined in net.vschool.xxx.servie.

Web layer operation: generally defined in net.vschool.xxx.action.

The following are examples of user modules:

net.vschool.user
net.vschool.user.dao
net.vschool.user.action
net.vschool.user.service
Copy after login

Writing specifications for second-class names (Class) Class names must use nouns. If a class name contains multiple words, then each word comes first The first letter is capitalized, and the subsequent letters are lowercase. The undulations are like a hump, and the person is named in the hump style. When naming a class, it must be accurate, concise, and easy to understand. Try to use complete words and avoid using abbreviations (except those that are generally recognized)

2.1 Naming of classes 2.1.1 General requirements 1. Choose a meaningful name that can quickly convey the purpose of the class.

2. Referring to the java camel case naming method, the first letter of the class name must be in uppercase. If the class name is a combination of multiple words, then the first letter of each word must be in uppercase. For example: StudentAnswer.java

3. When you want to distinguish between interface classes and implementation classes, you can add "Impl" after the class.

For example: Interface class: UserInterface.java Interface implementation class: UserInterfaceImp

4. It is recommended that entity classes have no suffix names.

2.1.2 Layering is often used in actual application application systems, Dao layer (database access), Service layer (business processing), Web layer (page control action class), the name of the class in each layer should be as Bring this layer suffix.

1. Dao layer

a. Interface class: defined in the form of JavaBean+Interface+Dao, that is, entity object+Interface+Dao.

For example: UserObject interfaceClass: UserInterfaceDao, where xxx is the module name.

b. Implementation class: defined in the form of JavaBean+Interface+Impl+Dao, that is, entity object

+Interface+Impl+Dao. For example: User object implementation class: UserInterfaceImplDao

2, Service layer

a, Interface class: defined in the form of Xxx+Interface+Service, that is, module+Interface+Service.

For example: User ManagementInterface class: UserMsgInterfaceServiec

b. Implementation class: defined in the form of Xxx+Interface+Impl+Service, that is, module+Interface+

Impl+Service. For example: User management implementation class: UserMsgInterfaceImplServiec

3. Web layer (action class)

a. Implementation class: defined in the form of Xxx+Operator+Action, that is, module + operation +Action. For example,

User module User+Delete operation Delete+Action = UserDeleteAction

2.1 Naming of variables 2.2.1 Ordinary variables 2.2.2.1 General requirements 1. Choose a meaningful name that can quickly convey the The purpose of the variable.

2. Refer to the java camel case naming method, the first letter starts with lowercase, and the first letter of each word is capitalized (except the first word).

2.2.2.2 Practical application 1. The basic structure of variable naming is typeVariableName, and a 3-character prefix is ​​used to represent the data type.

For example, define an integer variable: intDocCount, where int indicates the data type, followed by the ideographic English name, with the first letter of each word capitalized.

2. Variable usage skills:

a. Do not use the same variable in a function to represent two values ​​with different meanings.

b、除非是在循环中,否则一般不推荐使用单个字母作为变量名,i、j、k等只作为小型循环的循环索引变量。

c、避免用Flag来命名状态变量。

d、用Is来命名逻辑变量,如:blnFileIsFound。通过这种给布尔变量肯定形式的命名方式,使得其它开发人员能够更为清楚的理解布尔变量所代表的意义。

e、如果需要对变量名进行缩写时,一定要注意整个代码中缩写规则的一致性。例如,如果在代码的某些区域中使用intCnt,而在另一些区域中又使用intCount,就会给代码增加不必要的复杂性。建议变量名中尽量不要出现缩写。

2.2.2 静态变量 1、选择有意义的名字,能快速地传达该变量的用途。

2、参照java驼峰命名法,采用全部大写的形式来书写,对于采用多词合成的变量采用“_”来连接各单词。如:USER_LIST

2.3 方法的命名 2.3.1 一般要求 1、选择有意义的名字,能快速地传达该方法的用途。

2、参照java驼峰命名法,首字母以小写开头,每个单词首字母大写(第一个单词除外)。

2.3.2 实际应用 1、方法表示一种行为,它代表一种动作,最好是一个动词或者动词词组或者第一个单词为一个动词。

2、属性方法:以get/set开头,其后跟字段名称,字段名称首字母大写。如:getUserName()

3、数据层方法:只能以insert(插入),delete(删除),update(更新),select(查找),count(统计)开头,其他层方法避免以这个5个单词开头,以免造成误解。

4、服务层方法,根据方法的行为命名,只描述方法的意义,而不采用方法的目的命名。比如系统的添加新用户,用户可以前台注册,也可以管理员后台添加,方法会被重用,所以最好不要用使用register,采用add会更好写。避免使用与web层相关的方法。

5、Web层方法最好是贴近web的语言,如register,login,logout等方法。

三 注释的书写规范 (Javadoc) Java除了可以采用我们常见的注释方式(//、/* */)之外,Java语言规范还定义了一种特殊的注释,也就是我们所说的Javadoc注释,以/**开头,而以*/结束, Javadoc 注释可以被自动转为在线文档,省去了单独编写程序文档的麻烦。 推荐使用。

Javadoc注释主要涉及范围:类、属性、方法。

例如:

复制代码 代码如下:

package org.ietf.jgss;
import java.net.InetAddress;
import java.util.Arrays;
/**
 * 该类的整体性描述。
 *
 * @author 作者
 * @version 1.0, 05/22/07
 * @since 1.0
 */
public class ChannelBinding {
/**
 * 对该变量的备注信息
 */
private InetAddress initiator;
/**
 * 对该变量的备注信息
 */
private InetAddress acceptor;
/**
 * 对该变量的备注信息
 */
    private  byte[] appData;
    /**
     * 对该类的构造函数的备注信息。
     *
     * @param initAddr 对参数的备注。
     * @param acceptAddr对参数的备注。
     * @param appData对参数的备注。
     */
    public ChannelBinding(InetAddress initAddr, InetAddress acceptAddr,
              byte[] appData) {
         initiator = initAddr;
         acceptor = acceptAddr;
         if (appData != null) {
              this.appData = new byte[appData.length];
              java.lang.System.arraycopy(appData, 0, this.appData, 0,
                   appData.length);
         }
    }
    /**
     * 对该类的具体一函数的备注信息
     *
     * @param obj 参数的备注信息
     * @return 返回值的备注信息
     */
    public boolean equals(Object obj) {
         if (this == obj)
              return true;
         if (! (obj instanceof ChannelBinding))
              return false;
         ChannelBinding cb = (ChannelBinding) obj;
         return Arrays.equals(appData, cb.appData);
    }
}
Copy after login

四 其他书写规范

4.1 Jsp页面名称的书写规范 1.全部采用小写的英文字符和”_ ”组成。

2.整体采用模块名+操作的形式。如:user_view.jsp

3.Jsp页面尽可能与action的意思对应,如UserListAction 对应者user_list.jsp


相信看了这些案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!

相关阅读:

JS引擎运行时是什么样的

JS的使用过程中如何自定义console对象

H5中的弹窗无法用webview弹出怎么解决

The above is the detailed content of Questions and answers about camel case naming and JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template