How do I find a list of Hungarian notation prefixes?
I know that there are so many standards for writing code. And some policy tools (like FxCop) to check your writing statements.
What's the best Hungarian notation or any other snippets for writing code?
Like:
lbl in start of naming a Label
txt in start of naming a TextBox
, etc.
Based on the answers, is it a good Idea to use Hungarian notation or not?开发者_如何学运维
"Hungarian notation" has been the subject of many zealous debates in the programming community. Joel Spolsky has a well-noted article defending smartly used hungarian notation I find worth reading.
As for a list of prefixes to use in hungarian notation: I don't think a general list of such prefixes exist, as they would differ from programming language to programming language. The Wikipedia article lists a few; otherwise, I think you would have to refer to coding standards manuals of platforms / frameworks in your area that use hungarian notation.
With respect to your example with lbl and txt: this is not hungarian notation in the classical Charles Petzold sense, just prefixes/naming conventions.
Microsoft has a list of these. Excerpt:
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
The Microsoft Framework Design Guidelines, under General Naming Conventions says:
Word Choice
Do choose easily readable identifier names. For example, a property named HorizontalAlignment is more readable in English than AlignmentHorizontal.
Do favor readability over brevity. The property name CanScrollHorizontally is better than ScrollableX (an obscure reference to the X-axis).
Do not use underscores, hyphens, or any other nonalphanumeric characters.
Do not use Hungarian notation.
Hungarian notation is the practice of including a prefix in identifiers to encode some metadata about the parameter, such as the data type of the identifier.
At the lower abstraction level, of the Windows API, Charles Petzold's (fantastic) book "Programming Windows" has this to say about Hungarian Notation prefixes:
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
精彩评论