当前位置:网站首页>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 .
边栏推荐
- AvL树的实现
- 10、 Process management
- R语言使用dt函数生成t分布密度函数数据、使用plot函数可视化t分布密度函数数据(t Distribution)
- 多线程基础:线程基本概念与线程的创建
- Describe the process of key exchange
- 2022-2024年CIFAR Azrieli全球学者名单公布,18位青年学者加入6个研究项目
- AIRIOT物联网平台赋能集装箱行业构建【焊接工位信息监控系统】
- Penetration test information collection - CDN bypass
- R语言使用order函数对dataframe数据进行排序、基于单个字段(变量)进行降序排序(DESCENDING)
- Precautions for binding shortcut keys of QPushButton
猜你喜欢
Estimate blood pressure according to PPG using spectral spectrum time depth neural network [turn]
From 2022 to 2024, the list of cifar azrieli global scholars was announced, and 18 young scholars joined 6 research projects
AUTOCAD——中心线绘制、CAD默认线宽是多少?可以修改吗?
C#/VB.NET 给PDF文档添加文本/图像水印
Jushan database was among the first batch of financial information innovation solutions!
十、进程管理
使用cpolar建立一个商业网站(1)
None of the strongest kings in the monitoring industry!
Unlock 2 live broadcast themes in advance! Today, I will teach you how to complete software package integration Issues 29-30
ORACLE进阶(四)表连接讲解
随机推荐
287. Find duplicates
Master Xuan joined hands with sunflower to remotely control enabling cloud rendering and GPU computing services
Stm32+hc05 serial port Bluetooth design simple Bluetooth speaker
Cocos2d Lua smaller and smaller sample memory game
Markdown syntax for document editing (typera)
星诺奇科技IPO被终止:曾拟募资3.5亿元 年营收3.67亿
Some recruitment markets in Shanghai refuse to recruit patients with covid-19 positive
Crawling data encounters single point login problem
DOM Brief
Online notes
R语言ggplot2可视化时间序列柱形图:通过双色渐变配色颜色主题可视化时间序列柱形图
helm部署etcd集群
POJ 2208 six lengths of tetrahedron are known, and the volume is calculated
AUTOCAD——中心线绘制、CAD默认线宽是多少?可以修改吗?
Interpreting cloud native technology
手写一个的在线聊天系统(原理篇1)
Airiot IOT platform enables the container industry to build [welding station information monitoring system]
青龙面板最近的库
Penetration test information collection - basic enterprise information
44 colleges and universities were selected! Publicity of distributed intelligent computing project list