Recommendations on the Naming of Identifiers
Identifiers are defined:
oat the declaration of variables (variable name)
oat the declaration of user-defined data types
oat the creation of POUs (functions, function blocks, programs)
In addition to the general items to be considered when defining an identifier (refer to chapter General Information on variables declaration), consider the following recommendations in order to make the naming as unique as possible:
oUser-defined data types (DUTs) in Libraries
oFunctions, Function blocks, Programs (POU), Actions
For naming variables in applications and libraries, follow the Hungarian notation as far as possible.
Find for each variable a meaningful, short description. This is used as the base name. Use a capital letter for each word of the base name. Use small letters for the rest (example: FileSize).
Data Type |
Lower Limit |
Upper Limit |
Information Content |
Prefix |
Comment |
---|---|---|---|---|---|
BOOL |
FALSE |
TRUE |
1 bit |
x* |
– |
b |
reserved |
||||
BYTE |
– |
– |
8 bit |
by |
bit string, not for arithmetic operations |
WORD |
– |
– |
16 bit |
w |
bit string, not for arithmetic operations |
DWORD |
– |
– |
32 bit |
dw |
bit string, not for arithmetic operations |
LWORD |
– |
– |
64 bit |
lw |
not for arithmetic operations |
SINT |
–128 |
127 |
8 bit |
si |
– |
USINT |
0 |
255 |
8 bit |
usi |
– |
INT |
–32,768 |
32,767 |
16 bit |
i |
– |
UINT |
0 |
65,535 |
16 bit |
ui |
– |
DINT |
–2,147,483,648 |
2,147,483,647 |
32 bit |
di |
– |
UDINT |
0 |
4,294,967,295 |
32 bit |
udi |
– |
LINT |
–263 |
263-1 |
64 bit |
li |
– |
ULINT |
0 |
264-1 |
64 bit |
uli |
– |
REAL |
– |
– |
32 bit |
r |
– |
LREAL |
– |
– |
64 bit |
lr |
– |
STRING |
– |
– |
– |
s |
– |
WSTRING |
– |
– |
– |
ws |
– |
TIME |
– |
– |
– |
tim |
– |
TIME_OF_DAY |
– |
– |
– |
tod |
– |
DATE_AND_TIME |
– |
– |
– |
dt |
– |
DATE |
– |
– |
– |
date |
– |
ENUM |
– |
– |
16 bit |
e |
– |
POINTER |
– |
– |
– |
p |
– |
ARRAY |
– |
– |
– |
a |
– |
* intentionally for boolean variables x is chosen as a prefix in order to differentiate from BYTE and also in order to accommodate the perception of an IEC programmer (see addressing %IX0.0). |
Simple declaration
Examples for simple declarations:
bySubIndex: BYTE;
sFileName: STRING;
udiCounter: UDINT;
Nested declaration
Example for a nested declaration where the prefixes are attached to each other in the order of the declarations:
pabyTelegramData: POINTER TO ARRAY [0..7] OF BYTE;
Function block instances and variables of user-defined data types
Function block instances and variables of user-defined data types get a shortcut for the function block or the data type name as a prefix (for example: sdo).
Example
cansdoReceivedTelegram: CAN_SDOTelegram;
TYPE CAN_SDOTelegram : (* prefix: sdo *)
STRUCT
wIndex:WORD;
bySubIndex:BYTE;
byLen:BYTE;
aby: ARRAY [0..3] OF BYTE;
END_STRUCT
END_TYPE
Local constants
Local constants (c) start with prefix c and an attached underscore, followed by the type prefix and the variable name.
Example
VAR CONSTANT
c_uiSyncID: UINT := 16#80;
END_VAR
Global variables and global constants
Global variables are prefixed by g_ and global constants are prefixed by gc_.
Example
VAR_GLOBAL
g_iTest: INT;
END_VAR
VAR_GLOBAL CONSTANT
gc_dwExample: DWORD;
END_VAR
Structure
Basically, refer to the above description for variable names. Use the library namespace as prefix, when accessing a variable in your application code.
Example
g_iTest: INT; (declaration)
CAN.g_iTest (implementation, call in an application program
User-Defined Data Types (DUT) in Libraries
Structure
The name of each structure data type consists of a short expressive description (for example, SDOTelegram) of the structure.
Example (in library with namespace CAL):
TYPE Day :(
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY,
SUNDAY);
Declaration:
eToday: CAL.Day;
Use in application:
IF eToday = CAL.Day.MONDAY THEN
NOTE: Consider the usage of the namespace when using DUTs or enumerations declared in libraries.
Functions, Function Blocks, Programs (POU), Actions
The names of functions, function blocks, and programs are prefixed by an expressive short name of the POU (for example, SendTelegram). As with variables, the first letter of a word of the POU name should always be a capital letter whereas the others should be small letters. It is recommended to compose the name of the POU of a verb and a substantive.
Example
FUNCTION_BLOCK SendTelegram (* prefix: canst *)
In the declaration part, provide a short description of the POU as a comment. Further on, the inputs and outputs should be provided with comments. In case of function blocks, insert the associated prefix for set-up instances directly after the name.
Actions
Actions do not get a prefix. Only those actions that are to be called only internally that is by the POU itself, start with prv_.
Structure
For creating method names, the same rules apply as for actions. Enter English comments for possible inputs of a method. Add a short description of a method to its declaration. Start interface names with letter I; for example, ICANDevice.
NOTE: Consider the usage of the namespace when using POUs declared in libraries.