Gambas 命名约定
使用标准化的命名约定有助于简化我们程序员的工作,并减少其他人甚至我们自己在以后重访代码时阅读和理解源代码所需的工作。
使用此处概述的命名约定是可选的,但强烈建议将其作为Gambas中的良好编程实践。
Gambas的命名约定通常遵循
Hungarian notation 匈牙利表示法,使用大写
Camel case (也称为Pascal case),使用大写或小写前缀作为类型指示符。
这里有几个值得注意的例外。
Action
应该使用所有小写字母,用连字符(-)分隔单词。而且,函数和方法没有前缀。
这里是一个简短的总结。使用:
-
驼峰式大小写用于所有基本名称(除Actions外)。
-
Forms
, Classes
, Modules
和 Reports
的前缀只有一个大写字符。
-
Variables
以单个小写字符为前缀。
-
Controls
的前缀为三个小写字符。
一个类的所有私有变量名都应该加上 $
(美元符号)作为前缀。
示例
驼峰式大小写混合
MPrettyCode, Sub GetDateTitle()
Action
save-project, menu-tool
表单、类、模块和报表的大写前缀
FMain, CProjectList, MTest, RSales
变量
aList, bIsAvailable, cHash, fPhi, iCounter, sFirstName
表单控件和部件
btnCancel, btxSearchNames, lblWiki, cmxParent
变量名称的前缀
下表列出的变量名称前缀受编译器支持,但不是必需的。
示例
PRIVATE $iLast AS Integer
PRIVATE $sLast AS String
PRIVATE $hEditor AS Object
PUBLIC SUB Form_Open()
Dim dToday As Date = Date(Now)
Dim aNames As String[] = ["Goofy", "Mikey", "Donald"]
Dim nI As Integer
For nI = 0 To aNames.Max
Print aNames[nI]
Next
表单控件和部件名称的前缀
Form 上放置新的部件时, Gambas 给它们的命名就像 "Button1" "Button2" ...
在将方法分配给这些新元素之前,请将其重命名为 "btnStart" 或 "btnNew" ...
Type
|
Prefix
|
Button (ToolB., MenuB., RadioB., ColorB.,SwitchB., ToggleB.)
|
btn
|
ButtonBox
|
btx
|
CheckBox
|
chx
|
ColorChooser
|
clc
|
DnsClient, FtpClient, HttpClient
|
cln
|
ColumnView
|
clw
|
ComboBox
|
cmx
|
DocumentView
|
dcw
|
DrawingArea
|
dra
|
DirChooser
|
drc
|
DirView
|
drw
|
DirBox
|
drx
|
DateChooser
|
dtc
|
DateBox
|
dtx
|
Expander
|
exp
|
FileChooser
|
flc
|
FileView
|
flw
|
FontChooser
|
fnc
|
FontBox
|
fnx
|
Frame
|
frm
|
GridView
|
grw
|
HBox
|
hrx
|
HtmlView
|
htw
|
IconView
|
icw
|
ImageView
|
imw
|
Label (TextLabel, LCDLabel, URLLabel)
|
lbl
|
ListEditor
|
lse
|
ListView
|
lsw
|
ListBox
|
lsx
|
Menu
|
mnu
|
MessageView
|
msw
|
MaskBox
|
msx
|
MovieBox
|
mvx
|
PictureBox
|
pcx
|
ColorPalette
|
plt
|
Panel (HPanel, IconPanel, SidePanel, TabPanel, ToolPanel, VPanel)
|
pnl
|
ProgressBar
|
prb
|
Printer
|
prn
|
FileProperties
|
prp
|
ScrollArea
|
sca
|
ScrollBar
|
scb
|
ServerSocket, UdpSocket
|
sck
|
ScrollView
|
scw
|
Slider
|
sld
|
SliderBox
|
slx
|
SpinBar
|
spb
|
Splitter, HSplit, VSplit
|
spl
|
Spinner
|
spn
|
Spring
|
spr
|
SpinBox
|
spx
|
SerialPort
|
srp
|
TabStrip
|
stp
|
TableView
|
tbw
|
ToolBar
|
tlb
|
Timer
|
tmr
|
TerminalView
|
tmw
|
TimeBox
|
tmx
|
TreeView
|
trw
|
TextArea
|
txa
|
TextEditor, TextEdit
|
txe
|
TextView
|
txw
|
TextBox
|
txx
|
ValueBox
|
vlx
|
VBox
|
vrx
|
WebView
|
wbw
|
Workspace
|
wrk
|
Wizard
|
wzr
|
习俗
Generally, the three characters of the prefixes of form controls and elements derive from the following convention.
The first character followed by two phonically helpful letters if the name is simple; for example:
mnu
for
Menu
If instead the name is complex, then the first two characters will be determined by the first part of the name,
while the last one is based on the element's type:
Name (second part)
|
Suffix
|
Area
|
a
|
Bar
|
b
|
Box
|
x
|
Chooser
|
c
|
Editor
|
e
|
View
|
w
|
例外
There are exceptions that take the whole prefix from the second part of the complex name:
Name (second part)
|
Prefix
|
Client
|
cln
|
Palette
|
plt
|
Panel
|
pnl
|
Properties
|
prp
|
Socket
|
sck
|
Strip
|
stp
|