Gambas Documentation
Application Repository
Code Snippets
Compilation & Installation from source code
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 Object Model
Gambas Scripting
Gambas Server Pages
Gambas Unit Testing
Gambas Wiki Markup Syntax
Getting Started With Gambas
Getting Started With The IDE
Hall Of Fame
Housekeeping, cleaning up
Image Management In Gambas
Including Help Comments in Source Code
Installation from binary packages
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
Wayland and Gambas
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
Learning topics
Lexicon
README
Search the wiki
To Do
Topics
Tutorials
Wiki License
Wiki Manual
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:

Letter Type
a Array
b Boolean
c Collection
f Float
h Object (Handle)
i Integer, Long, Short, Byte.
n An integer storing a number of objects.
s String

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:

Letter Type
btn Button, use btnOK btnCancel for OK, Cancel
chk CheckBox
cvw ColumnView
cmb ComboBox
dwg DrawingArea
dlg FontChooser
edt GambasEditor
frm Frame
grd GridView
spl HSplit
iv IconView
lbl Label
lbl TextLabel
lst ListBox
lvw ListView
pan Panel
img PictureBox
opt RadioButton
svw ScrollView
spb SpinBox
tab TabStrip
tim Timer
txa TextArea
txt TextBox
txv textview
tbt ToolButton
trv TreeView
spl VSplit

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

variable Type Prefix
File fi
Process proc

Some Component prefix example

variable Type Prefix
Form frm
TextBox txtb
TextArea txta
ListBox lstb
ComboBox cbo
Timer tmr
Button but
ToggleButton tglbut
ToolButton tbut

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.

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