Constants serving local needs


Link to this posting

Postby Ursego » 19 Feb 2013, 22:20

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"
User avatar
Ursego
Site Admin
 
Posts: 143
Joined: 19 Feb 2013, 20:33



Ketones are a more high-octane fuel for your brain than glucose. Become a biohacker and upgrade yourself to version 2.0!



cron
Traffic Counter

eXTReMe Tracker