当前位置:网站首页>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
边栏推荐
- AcWing 135. Maximum subsequence sum (prefix sum + monotone queue to find the minimum value of fixed length interval)
- M-arch (fanwai 13) gd32l233 evaluation - some music
- Manuscript manuscript format preparation
- CLJ3-100ALH30剩余电流继电器
- Byte order - how to judge the big end and the small end
- Redis keys in PHP
- Doris记录服务接口调用情况
- Pytoch notes
- 套接字实现 TCP 通信流程
- MySQL锁查漏补缺
猜你喜欢

Clickhouse column basic data type description

Clickhouse column basic data type description

【藍橋杯單片機 國賽 第十一届】

【clickhouse专栏】基础数据类型说明

mysql中的索引show index from XXX每个参数的意义

DS18B20 digital thermometer (I) electrical characteristics, parasitic power supply mode and remote wiring

Unity connect to Microsoft SQLSERVER database

Unlimited growth, we will all go to the future | the 15th anniversary of the founding of InfoQ China

多普勒效应的基本原理

Selenium uses proxy IP
随机推荐
go基于阿里云实现发送短信
UI自动化测试中比较少见的异常记录
Architecture training module 7
logrotate日志轮转方式create和copytruncate原理
systemctl里万恶的203
AcWing 131. The largest rectangle in the histogram (monotone stack classic application template)
Relatively rare exception records in UI automation test
架构训练模块 7
正则表达式 | 浅解
重量级代理缓存服务器Squid
Windows10安装mysql-8.0.28-winx64
AcWing 1986. Mirror (simulation, ring diagram)
Pytorch笔记
Simple solution of regular expression
K53. Chapter 2 installing kubernetes v1.22 based on binary packages -- cluster deployment
Construction and construction of meta Universe System
Mcuxpresso develops NXP rt1060 (3) -- porting lvgl to NXP rt1060
一个人必须不停地写作,才能不被茫茫人海淹没。
MATLAB中stairs函数使用
B+ 树的简单认识