我知道编写代码有很多规范。还有一些策略工具(如FxCop)可以检查您的语句编写。
编写代码时最好使用匈牙利命名法或其他代码段,例如:
编写代码时最好使用匈牙利命名法或其他代码段,例如:
以lbl开头表示标签(Label)
以txt开头表示文本框(TextBox)
根据答案,使用匈牙利命名法是一个好主意吗?
以lbl开头表示标签(Label)
以txt开头表示文本框(TextBox)
根据答案,使用匈牙利命名法是一个好主意吗?
px
、count
和 rel
(或其他),可以使错误的组合立即可见 - 特别是当应用于函数时(getWidth()
返回相对值还是像素值?)。这才是真正的好处,而不是愚蠢的类型前缀。 - Pekka Prefix Object Type Example
-------------------------------------------------------
ani Animation button aniMailBox
cbo Combo box and drop down list box cboEnglish
chk Checkbox chkReadOnly
clp Picture clip clpToolbar
cmd (3d) Command button (3D) cmdOk (cmd3dOk)
dat Data control datBiblio
dir Directory list box dirSource
dlg Common dialog control dlgFileOpen
drv Drive list box drvTarget
fil File list box filSource
frm Form frmEntry
gau Gauge gauStatus
gpb Group push button gpbChannel
gra Graph graRevenue
grd Grid grdPrices
hsb Horizontal scroll bar hsbVolume
img Image imgIcon
ink Pen Ink inkMap
key Keyboard key status keyCaps
lbl Label lblHelpMessage
lin Line linVertical
lst List box lstPolicyCodes
mdi MDI child form mdiNote
mnu Menu mnuFileOpen
opt (3d) Option Button (3d) optRed (opt3dRed)
pic Picture picVGA
pnl3d 3d Panel pnl3d
shp Shape controls shpCircle
spn Spin control spnPages
txt Text Box txtLastName
tmr Timer tmrAlarm
vsb Vertical scroll bar vsbRate
Control
或 Form
的对象。 - IAbstract在Windows API的较低抽象级别上,Charles Petzold的(极好的)书籍《Programming Windows》对匈牙利命名法前缀有以下解释:
Prefix Data Type
-----------------------------------------------------------------
c char
by BYTE (unsigned char)
n short
i int
x, y int (used as x-coordinate or y-coordinate)
cx, cy int (used as x or y length; c stands for "count")
b or f BOOL (int); f stands for "flag"
w WORD (unsigned short)
l LONG (long)
dw DWORD (unsigned long)
fn function
s string
sz string terminated by 0 byte
h handle
p pointer