h1

Constants Usage

January 17, 2007

Hi Guys,

These are set of guidelines suggested by Krzysztof C and Microsoft Design Guidelines on the web on Constant Usage.

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 oneJ)

It also says that, using constants is better than not using them.

I also see that the Maintainability aspect should get the precedence over any other “good” technical practices behind constants.

Advertisements

2 comments

  1. Hi there.
    Yeah, well I don’t much like Cricket 🙂


  2. Anyway Laura, We lost the match:(



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: