Constants serving local needs

Share this topic:

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 (like ORDER_STATUS or INV_STATUS);
2. Code name (like OPEN or CLOSED).

Divide them by two underscores (in contrast to one underscore dividing words inside of each part) by this pattern: 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 = "CNCL"

constant string INV_STATUS__OPEN = "OPN"
constant string INV_STATUS__CLOSED = "CLS"
constant string INV_STATUS__CANCELED = "CNCL"
User avatar
Site Admin
Posts: 111
Joined: 19 Feb 2013, 20:33

Return to Elegant Code

Who is online

Users browsing this forum: No registered users and 2 guests

Constants serving local needs

Share this topic:

If you think that this site is not too bad, please LIKE it in Facebook. Thanks!

free counters

eXTReMe Tracker