Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Long Acronyms Should Be Pascal Cased

FxCop gets us on this all the time for constants:

Protected Const DEFAULT_DATE As String = "1/1/1800 12:00:00 AM"

Protected Const NAMES_FIRM_ADDR_RELATION As String =

"NamesFirmAddrRelation"

Protected Const AP_ADDR_RELATION As String = "FirmsApAddrRelation"

Protected Const FIRMS_FIRM_ADDR_RELATION As String =

"FirmsFirmAddrRelation"

Protected Const NAMES_SECONDARY_FIRM_ADDR_RELATION As String =

"NamesSecondaryFirmRelation"

Protected Const NAMES_PREFERRED_FIRM_ADDR_RELATION As String =

"NamesPreferredAddrRelation"

http://www.gotdotnet.com/team/fxcop/docs/rules.aspx?version=1.312&&url=/Naming/LongAcronymsShouldBePascalCased.html

I am getting tired of seeing these in FxCop so I can remove the rule, ignore

them or fix them.

What are other folks doing with casing for constants?

9 Comments

  • Exactly what you do. I exclude the rule for constants.

  • Pascal casing is used for exposed constants in the framework, e.g. double.MaxValue instead of double.MAX_VALUE, so I would recommend that you fix the FxCop violations. Remember that the constants listed will be exposed to any derived type, so they are part of your public API and you should make them consistent with the rest of the framework.

  • What you also have to be aware of, is there is another FxCop rule (or maybe its just written) that says not to expose public constants. I think that one is a bit odd, but I ignore it to. This isn't a breaking change, it only affects readability.

  • On a completely different note, it makes me shudder to see you storing a default date in a string.

  • Anon, it's a log story. We store it as a string and a date to support an existing app that we must run in parallel with for a while.

  • Kevin,



    "unless a field represents something that is truly constant, e.g. PI, then it could change in a future version. Clients will not be able to get such a change without being recompiled"



    Yes, this is why there is a rule that says not to expose public constants, because nothing is ever guaranteed not to change. I don't know where the rule is off the top of my head. It may not even be an FxCop rule, but its a good rule either way :)

  • I agree with the notion of not exposing constants publicly, and instead wrapping them behind a static property or something similar.



    But in answer to the original question I use the uppercased, underlined format too



    private const int THIS_IS_MY_CONSTANT_AND_DONT_FORGET_IT=0; // :snicker:

  • может у кого нить есть ещё информация по этому поводу??

  • 50 % discounts on all airtickets flights and hotels as well as all football matches
    email us at makitelove@yahoo.com

    no advance payment needed

Comments have been disabled for this content.