当前位置:网站首页>Camel case with Hungarian notation
Camel case with Hungarian notation
2022-07-06 18:56:00 【Life needs depth】
1. Hump naming rules
Hump nomenclature (camel-case) Once from Perl A mixed case format commonly used in languages , and Larry wall The best seller by et al 《program Perl》(o'Relly published ) The cover picture of is a camel , Hence the name . Hump method at C++ And other high-level languages , The underline method occupies the existing C Language system . The Hungarian method is win It is widely used among the old users of , However, the Hungarian method is less and less used in the current naming system . perhaps , To be exact, with the progress of Technology , This nomenclature gradually combined with the hump method to form a kind of suitable for today C++ And other high-level languages .
Hump type nomenclature is divided into big hump (big camel-case) And the small hump (little camel-case) Two kinds of . among , The big hump is characterized by capital letters at the beginning and at the back , Often used for class names 、 Function name 、 Properties and namespaces . Comparison , The small hump is characterized by the fact that the first letter of the first word is lowercase and the next letter is capital , Commonly used for local variables .
## Summary General
If you want to manage a slightly more complex system , A uniform set of foods 、 With hierarchy 、 Clear naming rules are essential and very useful tools .
Active in Biology 、 chemical 、 army 、 prison 、 underworld 、 A large number of knowledgeable predecessors in various fields such as terrorist organizations have proved the correctness of the above axiom with practical actions for countless times . Except God ( Suppose he could change the order of all things in the world ) outside , No one has the strength to disdain pictograms . In the highly abstract and complex activity of software development , The importance of naming rules is particularly prominent . A well-defined and complete set of 、 The naming conventions used throughout the project will greatly improve the readability of the source code and the maintainability of the software . Before introducing the details , Let's first explain the overall principles of naming conventions :
standard | explain |
Unity | When writing a sub module live derived class , Follow the naming convention style of its base class or overall module , Keep the naming convention style consistent throughout the module |
The identification consists of | The identifier shall be an English word or a combination thereof , It should be managed and leveled , You know what you mean , Use words appropriately and accurately |
The principle of minimizing the length and maximizing the amount of information | While keeping the meaning of an identifier clear , Try to shorten the length . The method is to use English accurately , Use word abbreviations at the same time |
Avoid being too similar | Do not appear similar identifiers that are only case sensitive , for example “i” And “I”,“function” And “Function” wait . |
Avoid duplicate names in different levels of scope | The program should not have local variables and global variables with identical names , Although the two functions are different, there will be no grammatical errors , But it's easy to misunderstand |
Correctly name mutually exclusive identifiers | Name mutually exclusive identifiers with correct antonyms , Such as :“nMinValue” and “nMaxValue”,“GetName()” and “SetName()” |
Avoid numeric numbers in names | Try to include numbers in your name , Such as value1,value2 etc. , Unless there is a logical need for numbering . This is to prevent programmers from being lazy , Refusing to name Dong Daojing leads to meaningless names ( Because number numbering is the easiest ). |
## class / structure class
Except for exceptional cases ( You do not want users to treat this class as a normal class ) Outside ,C++ class / The naming of structures should follow the following guidelines :
type | Naming method |
C++ class / Naming of structures | Class names are in uppercase letters “C" start , Followed by one or more words . For convenience of definition , The first letter of each word should be capitalized |
Recommended composition | It is recommended to use nouns or adjectives for the naming of classes + The form of a noun , for example :“CAnalyzer”,“CFastVector” wait |
Tradition C Structure naming | Tradition C The names of structures are all composed of capital letters , Underline between words , for example :SERVICE_STATUS |
differ C++ The concept of class , Conventional C A structure is just a way to tie a set of data together . Tradition C Naming rules for structures :
## function Function
type | explain |
Function name | The name of a function consists of one or more words , For convenience of definition , The first letter of each word should be capitalized |
Recommended composition | Function names should use verbs or verbs + Noun ( The verb object phrase ) In the form of . for example :“GetName()", "SetValue()","Reserve()" |
Protect member functions | Protected member functions should begin with an underscore “-” In order to show the difference between , for example :“————SetState()” |
Private member functions | Similarly , Private member functions should start with two underscores “__”, for example :“__DestoryImp()” |
Virtual functions | Virtual functions are used to Do start , for example :“DoRefresh()","_DoEncryption()” |
Callbacks and event handlers | Callbacks and time handlers are used to using words “On” start , for example :“_OnTimer()" |
## Variable
Variables should be the most used identifiers in the program , The naming convention for variables may be a set of C++ The most important part of the standard specification , The specific naming rules are as follows :
Variable name Variables have a scope prefix + Type prefix + One or more words make up . In order to define , The first letter of each word should be capitalized . For some simple and clear local variables , You can also use simplified methods , for example :i,j,k....
Scope prefix The scope prefix mainly indicates the visible range of a variable . Scopes can be as follows :
Prefix explain
nothing local variable
m_ Member variables of class (member)
sm_ Static member variable of class (static member)
s_ Static variables (static)
g_ External global variables (global)
sg_ Static global variables (static glboal)
gg_ Shared data segment global variables shared by processes (global global)
Unless you have to , Otherwise, you should use as few global variables as possible
Type prefix The type prefix indicates the type of a variable
Prefix explain
n Shaping and bit field variables (number)
e Enumerative variable (enumeration)
c Character variables (char)
b Boolean variables (bool)
f Floating point variables (float)
p Pointer variables and iterators (pointer)
pfn Especially for pointer variables of linear functions and function object pointers (pointer of function)
g Array (grid)
i Class (instance)
You can also define some special prefixes for frequently used classes , For example std::vector The intrinsic constraint variables of this container type , have access to v etc.
Type prefixes can be combined , for example “gc” Represents an array of characters ,“ppn” A pointer that represents a pointer that only wants to be shaped
char*/wchar_t* -> psz
char[]/wchar_t[] ->sz
sz Express string end of zero
S Structure SAddress
Prefix
type
describe
example
c
char
8 Bit character
cGrade
str string Character strName
ch
TCHAR
If _UNICODE Definition , Then for 16 Bit character
chName
b
BOOL
Boolean value
bEnable
n ,i
int
integer ( Its size depends on the operating system )
nLength
si
short int Short siSequ
n
UINT
Unsigned value ( Its size depends on the operating system )
nHeight
w
WORD
16 Bit unsigned value
wPos
f
float floating-point fRadius
d
double Double precision type dArea
l
LONG
Long integer
lOffset
ld
long double Long double precision ldRate
dw
DWORD
32 Bit unsigned integer
dwRange
p
*
The pointer
pDoc
lp
FAR*
Far pointer
lpszName
lpsz
LPSTR
32 Bit string pointer
lpszName
lpsz
LPCSTR
32 Bit constant string pointer
lpszName
lpsz
LPCTSTR
If _UNICODE Definition , Then for 32 Bit constant string pointer
lpszName
h
handle
Windows Object handle
hWnd
lpfn
callback
Point to CALLBACK Far pointer to function
?
if
Input file stream ifDataFile
of
Output file stream ofStuFile
sz
With "\0" Ending string szAppName
Recommended composition Variable names should use nouns or adjectives + Noun . for example :“nCode”,“m_nState”,“nMaxWidth”
## Constant
Constants are named with a type prefix + All capital letters , Underline between words , Such as :cMAX_BUFFER. The definition of type prefix is the same as that of variable naming rules .
## enumeration 、 union 、typedef
enumeration 、 Joint and typedef Statement generation is tiring. Your name consists of all capital letters , Underline between words , Such as :FAR_PROC
## macro 、 Enumerated values
Macro and enumeration values consist of all uppercase letters , Words are defined by underlining , Such as :ERROR_UNKNOWN,OP_STOP...
## Property
g_ Global variable/function
c_ Const variable
C class
m_ Member of struct/class
s_ Static variable
S Struct
## Componnet
Button btn
Label lbl
TextBox txt
## varibal
pointer p
char*
2. Underline naming rules
stay Linux The operating system is used C In the code written in language , Continue to use the underline coding specification according to the previous coding style . The difference between this coding standard and hump method lies in the semantic segmentation of words that form meaning between words , Underline use “_” Distinguish . In other variables, it is convenient to define and distinguish rules , There is no difference between the two .
边栏推荐
- 二叉搜索树
- Shangsilicon Valley JUC high concurrency programming learning notes (3) multi thread lock
- ORACLE进阶(四)表连接讲解
- The role of applet in industrial Internet
- Helm deploy etcd cluster
- Epoll () whether it involves wait queue analysis
- Nuc11 cheetah Canyon setting U disk startup
- Describe the process of key exchange
- 涂鸦智能在香港双重主板上市:市值112亿港元 年营收3亿美元
- Stm32+hc05 serial port Bluetooth design simple Bluetooth speaker
猜你喜欢
Noninvasive and cuff free blood pressure measurement for telemedicine [translation]
openmv4 学习笔记1----一键下载、图像处理背景知识、LAB亮度-对比度
CSRF vulnerability analysis
MySQL查询请求的执行过程——底层原理
Docker installation redis
Implementation of AVL tree
Solve DoS attack production cases
About NPM install error 1
[depth first search] Ji suanke: a joke of replacement
A wearable arm device for night and sleeveless blood pressure measurement [translation]
随机推荐
爬虫玩得好,牢饭吃到饱?这3条底线千万不能碰!
渲大师携手向日葵,远控赋能云渲染及GPU算力服务
Picture zoom Center
测试行业的小伙伴,有问题可以找我哈。菜鸟一枚~
About NPM install error 1
Numerical analysis: least squares and ridge regression (pytoch Implementation)
AcWing 3537.树查找 完全二叉树
Reptiles have a good time. Are you full? These three bottom lines must not be touched!
Hongke shares | plate by plate ar application in Beijing Winter Olympics
深度循环网络长期血压预测【翻译】
How are you in the first half of the year occupied by the epidemic| Mid 2022 summary
Mathematics in machine learning -- common probability distribution (XIII): Logistic Distribution
Method of accessing mobile phone storage location permission under non root condition
Example of implementing web server with stm32+enc28j60+uip protocol stack
Optical blood pressure estimation based on PPG and FFT neural network [translation]
First, look at K, an ugly number
JDBC驱动器、C3P0、Druid和JDBCTemplate相关依赖jar包
2022-2024年CIFAR Azrieli全球学者名单公布,18位青年学者加入6个研究项目
Interpreting cloud native technology
[matlab] Simulink the input and output variables of the same module cannot have the same name