Style Guide for GeneXus Development
by Daniel Monza
Table of Contents
- Naming
- Enumerated Domains
- Indent and Spacing
- Structured Data Types
- Strings
- Comments
- Commands and Functions
- Parameters
- Resources
- Companies that use this guide
- Translation
- Colaboradorators
- License
- Amendments
Naming
-
1.1 Names must be descriptive
The goal is to name stuff in a descriptive way
// bad
Proc: CliCre
// good
Proc: ClientCreate
-
1.2 Use PascalCase when naming objects,attributes and variables
// bad
createclient
// good
ClientCreate
-
1.3 Do not use underscore at the begining or end of any names for objects, attributes or variables.
This could misguide a programmer more familiar with other languages that theres some privacy meaning to the name.
// bad
&_CliNam = "John Doe"
&CliNam_ = "John Doe"
Proc: _ClientCreate
// good
&ClientName = "John Doe"
-
1.4 Enumerated domain names must start with the entity and then the type without abreviations, both in singular way. When defining a type we should be specific about the type of what.
This facilitates the definition of attributes and variables based on the domain (GeneXus will do it automatically). Also it makes it easier to reuse the domain - i.e. it's not just a Document-Type is the visibility-type of the document and other things might have the same visibility types.
// bad
DocumentsTypes
DocumentsType
DocType
// good
DocumentVisiblityType {public,private}
TransactionAccountType {credit, debit}
-
1.5 Name related procedures as Entity + Attribute (depending on the case) + Action + Complement.
This facilitates the selection of objects that deal with the same entity. Typical actions are Get, Set, Load (for an SDT), Insert, Update, Delete, etc. The difference between Set and Update is that Set refers to one attribute while Update refers to the entity
// bad
CliCre
UpdateClient
DateClient
// good
ClientUpsert
ClientDelete
ClientUpdateDateGet
ClientUpdateDateSet
ClientNameGet
ClientNameSet
ClientLoad
DocumentRecalculate
-
1.6 Use GIK nomenclature to name attributes. The use of 3 characters for the entity is recommendend when the names cannot exceed 20 characters and it has a clear and shared meaning.
This is the standard since the beginings of GeneXus
// bad
CreCliDte
DateCreationClient
// good
CliCreDte
// Better
ClientCreateDate or CliInsertDate
-
1.7 Transactions should be named after the entity in singular.
This faciliates working with Business Component. and it is required by some patterns GeneXus (ie.: K2BTools).
// bad
Trn:Clients
Trn:Products
// good
Trn:Client
Trn:Product
Indent and Spacing
-
2.1 Use tabs (tab) instead of "spaces". This way each developer can visualize the space as they prefer since the number of characters in a tab can be configured in GeneXus preferences.
Indent faciliates reading the source code, so if we follow a standard indentation it will make it easier for other developers to follow and understand the code.
// bad
if &DocumentOperationType = DocumentOperationType.Sale
msg("Sale")
endif
// bad
if &DocumentOperationType = DocumentOperationType.Sale
msg("Sale")
endif
// good
if &DocumentOperationType = DocumentOperationType.Sale
msg("Sale")
endif
-
2.2 Indent conditions in a for-each command
// bad
for each
where DocumentOperationType = DocumentOperationType.Sale
...
endfor
// bad
for each
defined by ClientName
...
endfor
// good
for each
where DocumentOperationType = DocumentOperationType.Sale
...
endfor
-
2.3 If a for each specifies a WHERE condition, or a DEFINED command, leave a blank space before the next line
// bad
for each
where DocumentOperationType = DocumentOperationType.Sale
if DocumentTotalAmount > &MaxCreditAmount
...
endif
endfor
// bad
for each
defined by ClientName
for each Document
...
endfor
endfor
// good
for each
where DocumentOperationType = DocumentOperationType.Sale
if DocumentTotalAmount > &MaxCreditAmount
...
endif
endfor
// good
for each
defined by ClientName
for each Document
...
endfor
endfor
-
2.4 Leave a space before each parm.
It makes the parm sentence more readable
// bad
parm(in:ClientId,out:&ClientName);
// good
parm( in:ClientId, out:&ClientName);
// bad
&Date = ymdtod(2017,01,01)
// good
&Date = ymdtod( 2017, 01, 01)
Enumerated Domains
-
3.1 Avoid the use of literals when there are many possible values
It makes the code easier to read and avoids typos and confusion
// bad
if &HttpResponse = "GET"
// good
// Create an enumreated domain HTTPMethod with possible values ( POST, GET)
if &HttpResponse = HTTPMethod.Get
Structured Data Types
-
4.1 Use New() when crating an SDT instead of a Clone(). Also do it before the SDT is used for the first time instead of at the end (even though GeneXus supports it)
It improves readibility
// &ClientCollection is aSDT:Client [List]
// &Client is a SDT:Cliente
// bad
for each Client
&Client.ClientName = ClientName
&ClientCollection.Add( &Client.Clone() )
endfor
// good
for each Client
&Client = new()
&Client.ClientName = ClientName
&ClientCollection.Add( &Client )
endfor