当前位置:网站首页>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
边栏推荐
- win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
- leetcode1020. Number of enclaves (medium)
- 升级版手机检测微信工具小程序源码-支持多种流量主模式
- Misc of BUU (update from time to time)
- 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
- TS Basics
- 3. Business and load balancing of high architecture
- Cookie Technology & session Technology & ServletContext object
- 1189. Maximum number of "balloons"
- leetcode1020. 飞地的数量(中等)
猜你喜欢

Cif10 actual combat (resnet18)

RichView TRVStyle 模板样式的设置与使用

After sharing the clone remote project, NPM install reports an error - CB () never called! This is an error with npm itself.

leetcode6109. 知道秘密的人数(中等,周赛)

变量的命名规则十二条

开源的网易云音乐API项目都是怎么实现的?

数据仓库建设思维导图

Interface automation test framework: pytest+allure+excel

leetcode35. 搜索插入位置(简单,找插入位置,不同写法)

ROS学习_基础
随机推荐
Bio model realizes multi person chat
[some special grammars about C]
Arduino tutorial - Simon games
kubernetes集群搭建Zabbix监控平台
因高额网络费用,Arbitrum 奥德赛活动暂停,Nitro 发行迫在眉睫
网络安全基础介绍
AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘/home/yolov5/models/comm
leetcode704. Binary search (find an element, simple, different writing)
Cookie Technology & session Technology & ServletContext object
Fast target recognition based on pytorch and fast RCNN
#systemverilog# 可综合模型的结构总结
The psychological process from autojs to ice fox intelligent assistance
Setting and using richview trvstyle template style
You deserve this high-value open-source third-party Netease cloud music player
Raspberry pie serial port login and SSH login methods
Prefix and array series
前缀和数组系列
树莓派串口登录与SSH登录方法
leetcode1020. Number of enclaves (medium)
Lesson 12 study notes 2022.02.11
https://www.bilibili.com/video/BV1XY411J7aG?p=8&vd_source=8e3e569f698756c0f7529e30f2af56ee