Thursday, November 16, 2006

Constants Usage Guidelines

I have prepared a Constants usage guidelines with the help of Krzysztof C from Microsoft:

1. If a value is constant in nature (never changes its value in its life time) make it a constant, such as Pi. [MSDN2: Microsoft design Guidelines]
2. If a literal used in two different assemblies make it public static read-only.
3. If a literal used in two different types (e.g. classes) in the same assembly make it a public constant and introduce a separate Constants code file.
4. If a literal used in two different members (method or a property) in a same type (e.g. class) make it a private field constant.
5. If a literal occurred in two places in a member, make it a local constant.
6. If a string literal is used at least once, consider it making a constant. (This guideline is the controversial one)

Any thoughts??


Post a Comment

<< Home