Dokumentaro de Gambaso
Compilation & Installation
Components
Documents
Frequently Asked Questions
Indekso de Lingvo
Language Overviews
LeguMin
Lexicon
Registro

Gambas Naming Conventions

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.

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.

Type Prefix
Array a
Boolean b
Collection c
Date d
Single, Float (floating point) f
Object (handle) h
Byte, Short, Integer, Long (integer numbers) i
An integer storing a number of objects. n
Pointer p
Variant v

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