473,385 Members | 1,907 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

propper casing of a constant

I always learned when you have a constant name it in all upper case like
this
PASSWORD_MAXIMUM_LENGTH

but FxCop is saying this isn't correct, but doesnt tell me the correct
"accepted" way in .net to name a constant... what is it?
Jun 28 '07 #1
6 1974
"Smokey Grindle" <no****@nospam.comschrieb
I always learned when you have a constant name it in all upper case
like this
PASSWORD_MAXIMUM_LENGTH

but FxCop is saying this isn't correct, but doesnt tell me the
correct "accepted" way in .net to name a constant... what is it?

There is no "correct". It's up to you, but you should make it consistently.
I prefer PasswordMaximumLength and probably most sources use it.
Armin

Jun 28 '07 #2
On Jun 28, 2:33 pm, "Smokey Grindle" <nos...@nospam.comwrote:
I always learned when you have a constant name it in all upper case like
this
PASSWORD_MAXIMUM_LENGTH

but FxCop is saying this isn't correct, but doesnt tell me the correct
"accepted" way in .net to name a constant... what is it?
Armin, most sources don't use ThisNotationAtAll.

You can do what you want but consistency will make you feel more at
home. Probably the most widely used and my personal favourite is
CONSTANT_NAME_IN_CAPITALS_WITH_UNDERSCORE.

This also provides more consistency than Armins approach as well since
as Microsoft use this convention and the library defines thousands of
constants in this fashion.

Jun 28 '07 #3
Constants are cased the same as variables in the camel/Pascal naming standards.
A constant is recognized by its carefully-selected name and (to a lesser
extent) how it is treated by IntelliSense and the compiler.

-----
Tim Patrick - www.timaki.com
Start-to-Finish Visual Basic 2005
I always learned when you have a constant name it in all upper case
like
this
PASSWORD_MAXIMUM_LENGTH
but FxCop is saying this isn't correct, but doesnt tell me the correct
"accepted" way in .net to name a constant... what is it?

Jun 28 '07 #4
On Jun 28, 10:33 am, Tim Patrick <inva...@invalid.com.invalidwrote:
Constants are cased the same as variables in the camel/Pascal naming standards.
A constant is recognized by its carefully-selected name and (to a lesser
extent) how it is treated by IntelliSense and the compiler.

-----
Tim Patrick -www.timaki.com
Start-to-Finish Visual Basic 2005
I always learned when you have a constant name it in all upper case
like
this
PASSWORD_MAXIMUM_LENGTH
but FxCop is saying this isn't correct, but doesnt tell me the correct
"accepted" way in .net to name a constant... what is it?
Welcome back Tim! I was starting to wonder what happened to you.

Thanks,

Seth Rowe

Jun 28 '07 #5
On Thu, 28 Jun 2007 14:30:53 -0000, Phillip Taylor
<Ph*****************@gmail.comwrote:
>On Jun 28, 2:33 pm, "Smokey Grindle" <nos...@nospam.comwrote:
>I always learned when you have a constant name it in all upper case like
this
PASSWORD_MAXIMUM_LENGTH

but FxCop is saying this isn't correct, but doesnt tell me the correct
"accepted" way in .net to name a constant... what is it?

Armin, most sources don't use ThisNotationAtAll.

You can do what you want but consistency will make you feel more at
home. Probably the most widely used and my personal favourite is
CONSTANT_NAME_IN_CAPITALS_WITH_UNDERSCORE.

This also provides more consistency than Armins approach as well since
as Microsoft use this convention and the library defines thousands of
constants in this fashion.
Maybe in c header files for Win32 constants, but not for
..Net, as far as I know.

From
http://www.irritatedvowel.com/Progra...Standards.aspx

"Same naming conventions as public/private member variables or
procedure variables of the same scope. If exposed publicly from a
class, use PascalCase. If private to a function/sub, use camelCase..

Do not use SCREAMING_CAPS

Why: This convention is consistent with the .NET Framework and is easy
to read. A sizable section of the Framework Design Guidelines is
dedicated to why they chose not to go the SCREAMING_CAPS route. Using
SCREAMING_CAPS also exposes more of the implementation than is
necessary. Why should a consumer need to know if you have an enum, or
(perhaps because they are strings) a class exposing public constants?
In the end, you often want to treat them the same way, and black-box
the implementation. This convention satisfies that criteria."

And here it is straight from the source:
http://blogs.msdn.com/brada/archive/.../03/67024.aspx

"We used the term SCREAMING CAPS to indicate an all upper case style.
Luckily this style (and name) did not survive in the final guideline."

If you like SCREAMING CAPS, go ahead, but you are violating the
official guidelines, even if you think otherwise.

You will find a bunch of them in places like
System.Drawing.NativeMethods,
but that is because they were ported from Win32.

Can you point me to a place in the framework where I can find a large
collection of .Net-originated constants that use SCREAMING CAPS(?)

Regards,

Joergen Bech

Jun 28 '07 #6
Smokey Grindle,
The naming rules in FxCop is based on the "Design Guidelines for Class
Library Developers":

..NET 3.0
http://msdn2.microsoft.com/en-us/library/ms229042.aspx

..NET 2.0 (VS 2005)
http://msdn2.microsoft.com/en-us/lib...42(vs.80).aspx

..NET 1.x (VS 2003)
http://msdn2.microsoft.com/en-us/lib...ke(vs.71).aspx

..NET 3.5 (VS 2008 aka Orcas)
http://msdn2.microsoft.com/en-us/lib...42(vs.90).aspx

Although I don't see a specific reference to Constant members, Public
Constants fall under the Public Members guidelines, which as the others have
pointed out are Pascal Case. In your case PasswordMaximumLength.
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Smokey Grindle" <no****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>I always learned when you have a constant name it in all upper case like
this
PASSWORD_MAXIMUM_LENGTH

but FxCop is saying this isn't correct, but doesnt tell me the correct
"accepted" way in .net to name a constant... what is it?

Jun 30 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrea M. Segovia | last post by:
I just compiled (but did not install) perl 5.8.0 on an SGI Origin 300 server (IP35) running IRIX 6.5.20m. Make test reported one test error, which I narrowed down to .../lib/ExUtils/t/Constant.t...
4
by: Shabs | last post by:
Hi, We are having this problem here on our project where we store all firstnames, lastnames in the oracle database in uppercase, when we retrieve the data to be used in web application and...
2
by: Visual Systems AB \(Martin Arvidsson\) | last post by:
Hi! Is it possible to enable Charater Casing in a ComboBox, if, how? As of now i am using KeyUp event to make sure that the char entered is Uppercase. Regards Martin Arvidsson
7
by: M O J O | last post by:
Hi, I can't figure out how to use the DesigMode property. I've searched Google and not found a soilid solution. Therefor I ask you - what is the propper way to find out if I'm in DesignMode??? ...
25
by: tsaar2003 | last post by:
Hi Pythonians, To begin with I'd like to apologize that I am not very experienced Python programmer so please forgive me if the following text does not make any sense. I have been missing...
3
by: lovecreatesbeauty | last post by:
Both `K&R C, 2nd' and `C: A reference manual, 5th' introduce the "hello, world" thing using the name "string-constant". But `ISO/IEC 9899:TC2' does not include this kind of thing in section `A.1.5...
33
by: desktop | last post by:
In the C++ standard sec 23.1.2 table 69 it says that erase(q) where q is a pointer to an element can be done in amortized constant time. I guess that is not worst case since std::set is...
18
by: sinbad | last post by:
hi, why does the following program gives an runtime error ,instead of compilation error. anyone please shed some light. thanks sinbad ------------------------------ int main()
7
by: John Koleszar | last post by:
Hi all, I'm porting some code that provides compile-time assertions from one compiler to another and ran across what I believe to be compliant code that won't compile using the new compiler. Not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.