当前位置:网站首页>Twelve rules for naming variables
Twelve rules for naming variables
2022-07-06 07:09:00 【Ana_ ing】
General rules
Rule one
Intuitively, you can spell , Look at the text and know the meaning , Easy to remember , Use English words or combinations , Pinyin is not recommended , English words should not be too complicated , It is recommended to use the abbreviation
Rule 2
The variable length conforms to “min_length && max_information”, such as Max_value Replace maxvalueuntiloverflow, Longer words can be abbreviated by removing vowels
Rule three
When the identifier consists of more than one word , The first letter of each word should be capitalized , The rest are in lowercase
for example int CurrentVal; // It looks clear and understandable
Rule 4
Try to avoid numbers in names , For example, I used to like to use value1,value2,value3 wait , Unless it is logically necessary , Like driver development and pins , Numbering is easier to use
Rule five
Global variables or functions that are commonly used among multiple files must be marked with a range limiting symbol ,( It is recommended to use the module abbreviation as the scope qualifier )
Rule 6
Symbol naming has two parts , Specification identifier prefix ( suffix )+ Meaning identification , Global variables to g or g+ Module abbreviation ( Capitalization ) Prefix , Variable names followed by the first capital letter .C The global variable in is an unstable factor , Be alert , Use prefix to explicitly identify variables as global , It can prompt . Add the abbreviation of the module before the name , When integrating and linking multiple modules , Avoid duplicate names of global variables between modules .
In local variable , Cycle count / Array subscripts are available i,j,k,m Sequential representation . in addition to , Prefix other variables to indicate variable type , There is no unified specification for prefixes ,p For the pointer ,pf Pointer to function ,f Single precision floating point ,db Double precision floating point ,u,s Represents unsigned and signed numbers respectively , namely unsigned And signed. In this way, its type can be seen from the variable name , And avoid some bug
Templates : Module name abbreviation _ Scope prefix | Data type prefix |【 Pointer prefix 】| Meaning identification | Array / Structure suffix
Rule seven
Scope prefix naming rules
Identifier type | Scope prefix |
Global variables | g |
File local variables | n |
Function local variable | f |
Local scope variables | a |
Global function | g |
Static functions | n |
Rule eight
Data type prefix naming rules
Prefix | suffix | data type | remarks |
bt | bit | ||
boolean | boolean | ||
char | char | ||
i | int | ||
s | shrot[int] | ||
l | long[int] | ||
u | unsigned[int] | ||
d | duoble | ||
f | float | ||
p | pointer | Pointer prefix | |
v | void | ||
st | enum | ||
st | struct | ||
st | union | ||
fp | function point | ||
_a | array of | ||
_st | typedef enum/struct/union |
Rule nine
The meaning of the variable consists of the identifier : The target word + Verb ( past participle )+ adverbial + The goal is
for example :DataDeletedFromSD
Function meaning and identifier constitute :
Verb ( Present tense )+ The target word + adverbial + The goal is
by the way , At the same time, Amway Yibo now really watches Grammar Videos
Rule 10
All macro definitions , Enumeration constant , Read only variables are all named in capital letters , Divide words with underscores .
for example
const int MAX_LENGTH = 100;
#define FILE_PATH “/usr/tmp”
Rule 11
Don't forget to initialize when defining variables . The compiler does not necessarily empty this memory when defining variables , Its value may be invalid data .
Rule 12
Considering habit , Local variables can be named in a common way , Is limited to n,i,j Etc. are used as loop variables .
2022 year 7 month 5 Japan 21:26:07 Administration building
边栏推荐
- Embed UE4 program into QT interface display
- 19.段页结合的实际内存管理
- Raspberry pie serial port login and SSH login methods
- Misc of BUU (update from time to time)
- Oracle数据库11gr2使用tde透明数据加密报错ora28353,如果运行关闭wallet会报错ora28365,运行打开wallet就报错ora28353无法打开wallet
- [daily question] 729 My schedule I
- hydra常用命令
- 升级版手机检测微信工具小程序源码-支持多种流量主模式
- [advanced software testing step 1] basic knowledge of automated testing
- PCL实现选框裁剪点云
猜你喜欢
First knowledge of OpenGL es learning (1)
Crawling exercise: Notice of crawling Henan Agricultural University
BUU的MISC(不定时更新)
Supporting title of the book from 0 to 1: ctfer's growth road (Zhou Geng)
[advanced software testing step 1] basic knowledge of automated testing
SEO学习的最好方式:搜索引擎
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
UWA pipeline version 2.2.1 update instructions
Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
随机推荐
At the age of 26, I changed my career from finance to software testing. After four years of precipitation, I have been a 25K Test Development Engineer
leetcode841. Keys and rooms (medium)
攻防世界 MISC中reverseMe简述
树莓派串口登录与SSH登录方法
BIO模型实现多人聊天
Oracle database 11gr2 uses TDE transparent data encryption to report an error ora28353. If you run to close the wallet, you will report an error ora28365. If you run to open the wallet, you will repor
多线程和并发编程(二)
Leetcode35. search the insertion position (simple, find the insertion position, different writing methods)
Uni app practical project
supervisor 使用文档
数据仓库建设思维导图
How to find a medical software testing institution? First flight software evaluation is an expert
网络安全基础介绍
简单描述 MySQL 中,索引,主键,唯一索引,联合索引 的区别,对数据库的性能有什么影响(从读写两方面)
呆错图床系统源码图片CDN加速与破解防盗链功能
Interface automation test framework: pytest+allure+excel
chrome查看页面fps
Prefix and array series
这个高颜值的开源第三方网易云音乐播放器你值得拥有
What is the biggest problem that fresh e-commerce is difficult to do now