Best Practices for the Naming of Identifiers

Overview

Identifiers are defined:

  • at the declaration of variables (variable name)

  • at the declaration of user-defined data types

  • at 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 in order to make the naming as unique as possible:

NOTE: The naming conventions and examples provided in the following paragraphs are based on good practices applied throughout the development of Schneider Electric libraries and correspond to the default convention queries that are used within EcoStruxure Machine Expert Code Analysis. Alternative naming conventions from other organizations are provided in parentheses in the following sections.

Variable Names

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

bit string, not for arithmetic operations

SINT

–128

127

8 bit

si

arithmetic integer data type, 8-bit

USINT

0

255

8 bit

usi

arithmetic integer data type, 8-bit

INT

–32,768

32,767

16 bit

i

arithmetic integer data type, 16-bit

UINT

0

65,535

16 bit

ui

arithmetic integer data type, 16-bit

DINT

–2,147,483,648

2,147,483,647

32 bit

di

arithmetic integer data type, 32-bit

UDINT

0

4,294,967,295

32 bit

udi

arithmetic integer data type, 32-bit

LINT

–263

263-1

64 bit

li

arithmetic integer data type, 64-bit

ULINT

0

264-1

64 bit

uli

arithmetic integer data type, 64-bit

REAL

32 bit

r

arithmetic floating-point data type, 32-bit

LREAL

64 bit

lr

arithmetic floating-point data type, 64-bit

STRING

s

Single-byte character string of variable length (default setting: 80 characters)

WSTRING

ws

Double-byte character string of variable length (default setting: 80 characters)

TIME

tim

time duration, 32-bit

LTIME

ltim

time duration, 64-bit

  • TIME_OF_DAY

  • TOD

tod

time of day, 32-bit

  • LTIME_OF_DAY

  • LTOD

ltod

time of day, 64-bit

  • DATE_AND_TIME

  • DT

dt

date and time

  • LDATE_AND_TIME

  • LDT

ldt

DATE

  • dat

  • d

calendar date

LDATE

  • ldat

  • ld

calendar date

Enumeration

et (e)

POINTER

p

ARRAY

a

Structure

st

Function block

fb

Interface

if (itf)

Union

ut

* 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: stSDO).

Example

stSDOReceivedTelegram: ST_SDOTelegram;
TYPE ST_SDOTelegram : 
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_ (g_) and global constants are prefixed by Gc_ (gc_).

Example

VAR_GLOBAL
  G_iTest: INT;
END_VAR
VAR_GLOBAL CONSTANT
  Gc_dwExample: DWORD;
END_VAR

Variable Names in Libraries

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 the corresponding type prefix (also refer to POU Prefix) and a short, meaningful name (for example, ET_Day) of the structure.

Example (in library with namespace CAL):

TYPE ET_Day :(
MONDAY,
TUESDAY,
WEDNESDAY,
THURSDAY,
FRIDAY,
SATURDAY,
SUNDAY);

Declaration:

etToday: CAL.ET_Day;

Use in application:

IF etToday = CAL.ET_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 consist of the corresponding type prefix (also refer to POU Prefix) and a short, meaningful name of the POU (for example, FB_SendTelegram). As with variables, the first letter of a word of the POU name should be an uppercase letter whereas the others should be lowercase letters. For example, compose the name of the POU of a verb and a substantive to clearly indicate the operation of the function block.

Example

FUNCTION_BLOCK FB_SendTelegram

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_.

POUs in Libraries

Structure

For creating method names, the same rules apply as for actions. Enter comments for possible inputs of a method. Add a short description of a method to its declaration. Start interface names with prefix IF_ (I); for example, IF_CANDevice.

NOTE: Consider the usage of the namespace when using POUs declared in libraries.