Page 1 of 1

Constants serving local needs

PostPosted: 19 Feb 2013, 22:20
by Ursego
Build names of local and instance (used only in a particular object, NOT all over the application) constants from 2 parts:

1. Constants group aka family (like ORDER_STATUS or INV_STATUS);
2. Code name (like OPEN or CLOSED).

Divide these parts by two underscores (in contrast to one underscore which divides words inside of each part): CONSTANTS_GROUP__CODE_NAME.


This method:

• Helps code readers to distinguish between two the parts.
• Allows many constants with a same name to co-exist in a same scope, for example:

Code: Select all
constant string ORDER_STATUS__OPEN = "OPN"
constant string ORDER_STATUS__CLOSED = "CLS"
constant string ORDER_STATUS__CANCELED = "CNC"

constant string INV_STATUS__OPEN = "OPN"
constant string INV_STATUS__CLOSED = "CLS"
constant string INV_STATUS__CANCELED = "CNC"