当前位置:网站首页>Naming specification / annotation specification / logical specification
Naming specification / annotation specification / logical specification
2022-06-12 11:31:00 【Qiao Duoduo】
In order to improve the readability of the code , And other follow-up personnel for easy search 、 Modify the code , The following specifications can be followed :
1. Naming specification :
(1)id/class Use the middle dash nomenclature , for example article-title、article-content; Hump naming method is adopted for variable naming, for example articleList、articleInfo
(2) Name in English instead of Chinese , For example, the page header should be named header, instead of toubu
(3) Try not to abbreviate , Unless it is a word that can be understood at first sight , for example nav
(4) The naming of variables should use easy to understand words or phrases , Avoid using data、value And so on , Use the singular, not the plural . For example, using articleInfo、articelList Don't use articlesList、articleLists
(5) for fear of class The repetition of names , When naming, it usually takes the name of the parent element class Name as a prefix , for example :
<div class="column>
<h3 class="column-title></h3>
<div class="column-content></div>
</div>
(6) To avoid ambiguity , When naming variables, try to use word combinations . for example : use provinceCode For the province code, use provinceName Indicates the name of the province , If only province, It is easy to confuse the data stored in this variable . Words that are easy to understand do not have to use word combinations , for example phone It usually means telephone number .
(7) Method name : Verb + Noun , for example getArticleList Means to get the article list 、submitArticleInfo Means to submit article information 、goAddPage Jump to the new page 、showDetailModal/closeAddModal To show / Close the pop-up window for details
2. Annotation specifications
(1) Module annotation : Add comments at the beginning or end of the module , Description plus “start”、“end”, Easy to locate . for example :
<!-- Navigation start-->
...
<!-- Navigation end-->
/* Article list style start*/
...
/* Article list style end*/
3. Logical norms
Use if When branching statements , To avoid excessive code embedding ( Constantly indent to the right ), Use the writing method of negative logic judgment , And handle exceptions ; The main logic should be positive . The code example is as follows :
if( Cannot continue to execute logical decision expression ) {
/* Error prompt or throw exception */
return
}
The correct business logic continues
边栏推荐
- [the 11th national competition of Blue Bridge Cup single chip microcomputer]
- arm各种交叉编译工具的区别
- MySQL锁查漏补缺
- DS18B20数字温度计 (一) 电气特性, 供电和接线方式
- 890. find and replace mode
- UI自动化测试中比较少见的异常记录
- Distributed storage exploration
- AcWing 128. Editor (to effectively modify the specified position in the top stack)
- 字节序 - 如何判断大端小端
- 网络的拓扑结构
猜你喜欢

Clj3-100alh30 residual current relay

^34 scope interview questions

无限生长,我们都将奔赴未来 | InfoQ中国成立15周年

Socket implements TCP communication flow

^33 variable promotion and function promotion interview questions

AcWing 128. Editor (to effectively modify the specified position in the top stack)

Signal relay rxsf1-rk271018dc110v

你需要社交媒体二维码的21个理由

manuscript手稿格式准备

Logrotate log rotation method create and copyruncate principles
随机推荐
Reentrantlock source code analysis
Sendmail Dovecot 邮件服务器
套接字编程Udp篇
Problems in cross validation code of 10% discount
ReentrantLock源码分析
Lambda expression | shallow solution
Go sends SMS based on alicloud
Heavyweight proxy cache server squid
AcWing 135. Maximum subsequence sum (prefix sum + monotone queue to find the minimum value of fixed length interval)
NLP data set download address for naturallanguageprocessing
M-arch (fanwai 13) gd32l233 evaluation - some music
MySQL锁查漏补缺
Golang Foundation (7)
Golang基础(7)
redis 總結
When you have a server
Clickhouse column basic data type description
Shardingjdbc-5.1.0 monthly horizontal table splitting + read-write separation, automatic table creation and node table refresh
Socket implements TCP communication flow
Clickhouse column basic data type description