Tips_namingconventions   >   Miscellaneous

Abbreviations

To make your code easy for other programmers to follow you should limit the use of abbreviations in your class, method, and variable names.

If the abbreviated form of a word only saves typing 2 letters use the full name. If the abbreviated form of a word saves typing 3 letters only declare an abbreviation if the word is a frequently used in your code.

If you use abbreviations be consistent. Using the abbreviation and not the full name. e.g. If you decide to use the abbreviations 'Col' and 'Var' then don't use 'Column' or 'Variable' in any of variable names.

Whether or not to stick with abbreviations for method and class names is debatable. $createSubLib or $createSubLibrary? $setPKey or $setPrimaryKey? I would lean towards the full name rather the abbreviation for method and class names, but I wouldn't make it a hard and fast rule. If the class or method name is getting too long you may need to use some abbreviations. Code readability is the main concern.

The following is a list of abbreviations used.

Acronyms

As with abbreviations you should be consistent with using acronymns. Always use the uppercase form of acronyms in your class, method, and variable names.

The following acronyms are used:

% Prefixed Variables

You can create a local variable on the fly while you are entering code by prefixing the not yet created variable in your code with a % character. Omnis creates a % prefixed local variable as you leave the code editor field where you typed the % prefixed variable. A single % prefix creates a floating decimal number datatype local variable. A double %% prefix creates a character datatype local variable.

This is a handy feature, but you should not leave the % prefixed local variable as it is. If you reuse the % prefixed variable later on in the method and incorrectly type the % prefixed variable name, Omnis creates a second % prefixed local variable matching your typo. You can imagine the problems that will follow when you have to debug your code.

Immediately after creating the a % prefixed variable, go to the local variable and remove the % prefix from the variable name. For single % prefixed variables you likely wanted an integer datatype so you should also change the floating point number datatype to integer. Using floating point numbers when you really need an integer can cause code errors and reduces performance when used as a loop counter.

The one exception where you will see % prefixed variables for loop counters.

Consistent Names

Using names consistently is important for ensuring code readability. This is a minor point, but the effort to use the declared format of the name is no more effort than using a different format. Once you get into the habit of using the declared format you won't find yourself second guessing what form to use. The following is a list of often used names and the declared format for the name.

Language

What language do we use to write code? If we want to share libraries we should use a common language.

I am a Canadian and we use en-GB (British English) spelling in our country, but the fact is that the common language of the computing world is en-US (US English). People using computer programs in non-English speaking countries are often faced with en-US manuals (especially if you are a developer) so en-US isn't completely new to them. For this reason the I use en-US for writing code and documentation. The choice is yours.

Omnis Naming Conventions

Omnis uses naming conventions for its method parameters as follows:

Examples of the Omnis naming conventions are as follows:

$search(calculation[,bFromStart=kTrue, bOnlySelected=kFalse, bSelectMatches=kTrue, bDeselectNonMatches=kTrue])

$lvardef.$add(cName,type,subtype,iMaxLength,blsparameter)
$menus.$remove(rItem)

$cols.$add(fieldname|cName[,type,subtype,iMaxLength])

Note: | = or