Coding style is a set of rules or guidelines applied when writing source code. Following a specified coding style helps:
To read and understand the source code
To avoid and find programming issues
To maintain the source code
Based on the Programming Guidelines (Naming Conventions, Prefixes) for source code, variable name convention queries are available to verify the suggested variable name per data type and variable scope.
For convention verification, the variable name is combined with its linked data type and the scope where the variable is defined in.
Scopes:
Local variable scope: No special scope prefix (VAR ... END_VAR)
Input variable scope: i_ as prefix (VAR_INPUT ... END_VAR)
Output variable scope: q_ as prefix (VAR_OUTPUT ... END_VAR)
In-/Output variable scope: iq_ as prefix (VAR_IN_OUT_ ... END_VAR)
Global variable scope: G_ as prefix
Global constants scope: Gc_ as prefix
etc.
Variable name prefixes based on data type:
INT: i as prefix
DINT: di as prefix
UDINT: udi as prefix
REAL: r as prefix
LREAL: lr as prefix
Function block: fb as prefix
POINTER TO: p as prefix
etc.
VAR
iMyVariable1: INT;
uiMyVariable1: UINT;
rMyVariable1: REAL;
piMyVariable7: POINTER TO INT;
END_VAR
VAR_INPUT
i_iMyVariable2: INT;
i_uiMyVariable2: UINT;
i_rMyVariable2: REAL;
END_VAR
VAR_IN_OUT
iq_iMyVariable3: INT;
iq_uiMyVariable3: UINT;
iq_rMyVariable3: REAL;
END_VAR
VAR_OUTPUT
iq_iMyVariable2: INT;
iq_uiMyVariable2: UINT;
iq_rMyVariable2: REAL;
END_VAR