Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6837769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:31:00+00:00 2026-05-26T23:31:00+00:00

I was often wondering about the right way to do this: For example, in

  • 0

I was often wondering about the right way to do this:

For example, in my program I have around 100 constants (or enums) that are used in some calculation. They should preferrably be stored in one place. They can be grouped hierarchically, for example:

System3 / Rules / Rule7 / ParameterXY / MaxAverageValue

Naturally, I want those values to be accessible while coding, so storing them in some kind of ressource is not really an option.

As far as I could tell, this can be done with:

  • very long constant names
  • nesting classes
  • namespaces

Using names is quite ugly, and it’s not really well maintainable. I find nesting classes a nice way to do it, but some stylecop/fxcop rules forbid that, so this must be “bad” in some way. Lastly, I find the suggested alternative, using namespaces, not terribly nice neither. Imho it creates masses of folders and files that each contain almost nothing. And I don’t like when 50 sub-namespaces pop up in the assembly reflector.

So.. how do you do this kind of task? What would you suggest?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T23:31:01+00:00Added an answer on May 26, 2026 at 11:31 pm

    very long constant names

    This is sort of gross, but at least it is discoverable. All your code would reside in the same place so you wouldn’t have a problem finding it.

    I find nesting classes a nice way to do it, but some stylecop/fxcop rules forbid that, so this must be “bad” in some way

    One reason it is is bad because automated code generation/code inspection tools are harder to work with. Another reason is that it is harder to discover these with Intellisense.

    The most important reason this is bad is because a nested class should be strongly associated in an object-oriented dependency sense for the layout be make sense logically. In all but some rare cases (e.g. Enumerator classes) it won’t make sense. In your case it also doesn’t make sense because your classes don’t really have any behavior or object orientation at all – they’re just a hierarchy of constants.

    Namespaces

    For the problem you described, this is the best way to handle it. You get the least clutter per-level, and you get Intellisense while typing so you can see what you’re narrowing down to while descending through the hierarchy.

    Imho it creates masses of folders and files that each contain almost nothing

    If you really need a huge pool of constants, and it doesn’t make sense to bind them to other parts of your application, then this is one of the rare cases that I’d abuse the one-file-per-class and one-folder-per-namespace rules. The only reason you’re even stuffing them into classes at all is because .Net doesn’t have support for global variables.

    Another suggestion

    Do you have domain-specific objects that these constants belong on instead? E.g. is there any logic related to the System3 / Rules / Rule7 class? Is that not some sort of actual business rule that you should embody with its own class?

    If you can arrange your code so that you have a thicker domain model, then the most logical place to put your constants is on the classes that embody the corresponding domain logic.

    If it doesn’t make sense to have a thick domain, you have fully generic rules processing, and you are relying on constants to feed your business engine logic, then you have a data-driven application. This means you should store your data in configuration files, not in code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use a pattern that looks something like this often. I'm wondering if this
I'm wondering about standards or commonalities for various common elements on webpages that have
Had a question that I've often wondered about. Is it better to have multiple
I have a program that collects objects over time. Those objects are often, but
Something I don't enjoy about programming is learning a new API. For example, right
I was just wondering what software libraries are often used in professional commercial game
When I write SQL queries, I find myself often thinking that there's no way
I think that here answer will come from experience. I am right know wondering
I have about 15~20 member variables which needs to be accessed, I was wondering
It's not that I'm not familiar with the concept but I'm wondering about what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.