Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation
Components
Controls pictures
Deprecated components
Developer Documentation
Development Environment Documentation
Documents
About The Best Formula In The World
Architecture details
Benchmarks
Books
By Reference Argument Passing
Compatibility between versions
Creating And Using Libraries
Database Datatype Mapping
Database Request Quoting
Date & time management
Dates and calendars
DBus and Gambas
Differences Between Shell And Exec
Differences From Visual Basic
Distributions & Operating Systems
Drag & Drop
DrawingArea Internal Behaviour
External functions datatype mapping
Frequently Asked Questions
Gambas Farm Server Protocol
Gambas Mailing List Netiquette
Gambas Markdown Syntax
Gambas Naming Conventions
Gambas Object Model
Gambas Scripting
Gambas Server Pages
Gambas Unit Testing
Gambas Wiki Markup Syntax
Getting Started With Gambas
Hall Of Fame
Image Management In Gambas
Including Help Comments in Source Code
Interpreter limits
Introduction
Just In Time Compiler
Just In Time Compiler (old version)
License
Localisation and Internationalization
Mailing Lists & Forums
Naming Conventions
Network Programming
ODBC Component Documentation
PCRE Pattern Syntax
Porting from Gambas 2 to Gambas 3
Previous News
Project Directory Structure
Release Notes
Reporting a problem, a bug or a crash
Rich Text Syntax
Screenshots
Text highlighting definition file syntax
The Program has stopped unexpectedly by raising signal #11
Variable Naming Convention
WebPage Syntax
Web site home page
What Is Gambas?
Window & Form Management
Window Activation & Deactivation
Window Life Cycle
XML APIs
Error Messages
Gambas Playground
How To's
Language Index
Language Overviews
Last Changes
Lexicon
README
Search the wiki
To Do
Topics
Tutorials
Wiki License
Wiki Manual

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