Using a standardized naming convention helps to simplify our work as programmers and reduce the effort needed to read and understand the source code by others and even ourselves when we later revisit the code.
When you write a project, you
must have a naming convention which is the same for the entire project. The contents of that naming convention is not important per se as the choice of naming convention is up to you. Just be sure you use it consistently within a project.
Following are some naming convention examples used, and written by, different people to give you some guidance and ideas.
Naming Conventions Used in the Code for the IDE
Created by Benoît Minisini
The naming conventions are not required by the compiler.
But programs which use the following naming conventions are easier to read by other programmers
who want to understand the program.
Variable names
All private variable names of a class start with $
The first letter is lower case and should depend on the type of the variable:
Examples
PRIVATE $iLast AS Integer
PRIVATE $sLast AS String
PRIVATE $hEditor AS Object
PRIVATE $sOldVal AS String
PRIVATE $bFreeze AS Boolean
PUBLIC SUB Form_Resize()
DIM iWidth AS Integer
Form element names
When placing a new form element. Gambas gives it a name like "Label1" "Label2" ...
Before you assign a method to the new element,
you rename it to "btnStart" or "lstAddressSelect".
The first two or three lower case letters should
be given according to this definition:
A project which uses this style is the Gambas IDE (under /app/src/gambas3 in the source tree). It contains lots of more prefixes for various controls.
Variable Naming Convention by Fabien Bodard
Written by Fabien Bodard
It's simply how you give name to your variables ! What method, to make difference between two type of variables or two type of objects.
You need to adopt a convention.
If you call each variable, according to the impultion of the moment, not only you will have names that you don't remember, but you will search astute variable name at place of searching astute algorithms. A calling convention need to be automatic. In fact, two person that use the same calling convention would have the same variables name.
Most of the time, bad calling convention goes from pair with a bad code.
By default, Gambas give a default name to the widgets, like button1, textbox1, etc... and then incrementing the value when you add a new component in the IDE. But the problem with this system is that your code is really difficult to interpret or to debug...
But all is not lost at this time... i've maybe a soluce for you :-).
The hungarian convention for Gambas
The hungarian convention is a good one. You have probably seen this convention in some Microsoft Visual Basic exemples sources. I don't say it's the best one, but i've use it in some other languages php, fortran, and it got fine on Gambas.
All the users of the hungarian convention that I know have in a first time hated it. But whatever your opinion is, you will not regret having learned to read Hungarian.
This convention was created by Charle Simonyi, veteran of developement at Microsoft and and Hungarian of birth.
It implies that the variables comprises two parts: a basic type in small letters indicating the kind of variable, and a qualifier with initial in capital letter which distinguishes a variable of the other of the same variables. Then you can add a letter like
$ at the beginning to distingish the global variables.
Examples
An integer variable that will be used to locate something
iPos
An integer variable that will be used to locate something in a file and another in a textarea
iFilePos
iLinePos
A form for save a file as...
frmSaveFileAs
Prefix convention for common variables types
variable type
|
Prefix
|
Integer
|
i
|
Float
|
f
|
Boolean
|
b
|
Byte
|
bt
|
Short
|
sh
|
Long
|
l
|
Single
|
sng
|
Variant
|
v
|
Pointer
|
ptr
|
String
|
s
|
Date
|
date
|
Object
|
o
|
Prefixe convention for array or collection variable type
variable Type
|
Prefix
|
Static array
|
ar + type prefix
|
Integer[]
|
ari
|
Float[]
|
arf
|
Boolean][]
|
arb
|
Byte][]
|
arbt
|
Short[]
|
arsh
|
Long[]
|
arl
|
Single[]
|
arsng
|
Variant[]
|
arv
|
String[]
|
ars
|
Date[]
|
ardate
|
Object[]
|
aro
|
Collection
|
col
|
Special types
Some Component prefix example
Gambas Naming Conventions by Gianluigi
Use of the naming convention outlined here is optional but it is strongly encouraged as good programming practice in Gambas.
The Gambas naming convention generally follows
Hungarian notation using upper
Camel case (also known as Pascal case) with an uppercase or lowercase prefix as a type indicator.
There are a couple of notable exceptions to this. An
Action
should use all lowercase letters with a dash (hypen) separating words. And, functions and methods are not given a prefix.
Here is a short summary. Use:
-
Camel case for all base names (except for Actions).
-
A Prefix of only one uppercase character for
Forms
, Classes
, Modules
and Reports
.
-
A Prefix of a single lowercase character for
Variables
.
-
A prefix of three lowercase characters for
Controls
.
All private variable names of a class should additionally be prefixed with $
(dollar sign).
Examples
Camel case
MPrettyCode, Sub GetDateTitle()
Action
save-project, menu-tool
Upper case prefix for Forms, Classes, Modules, and Reports
FMain, CProjectList, MTest, RSales
Variables
aList, bIsAvailable, cHash, fPhi, iCounter, sFirstName
Form Controls and elements
btnCancel, btxSearchNames, lblWiki, cmxParent
Prefixes for variable names
The variable name prefixes listed in the table below are supported by the compiler but are not required.
Example
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
Prefixes for form control and element names
When placing a new
Form element. Gambas gives it a name like "Button1" "Button2" ...
Before you assign a method to the new element, you rename it to "btnStart" or "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
|
Convention
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
|
Exceptions
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
|