473,800 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

propper casing of a constant

I always learned when you have a constant name it in all upper case like
this
PASSWORD_MAXIMU M_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 1994
"Smokey Grindle" <no****@nospam. comschrieb
I always learned when you have a constant name it in all upper case
like this
PASSWORD_MAXIMU M_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 PasswordMaximum Length 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_MAXIMU M_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 ThisNotationAtA ll.

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_I N_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_MAXIMU M_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...@invali d.com.invalidwr ote:
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_MAXIMU M_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.com wrote:
>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_MAXIM UM_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 ThisNotationAtA ll.

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_WIT H_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 PasswordMaximum Length.
--
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******** ********@TK2MSF TNGP03.phx.gbl. ..
>I always learned when you have a constant name it in all upper case like
this
PASSWORD_MAXIMU M_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
1910
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 using harness. I ran the test separately, and got the following detailed error report: .../lib/ExtUtils/t/Constant....ok 6/51Confused test output: test 6 answered after test 44
4
1978
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 email letters, we do a propercase on the names. But, for names like O'Rieley, McDonald, propercasing the name returns Orieley, Mcdonald. Our client/customer requires us to display it as ORieley, McDonald. Did anybody come across a similar situation or...
2
2270
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
1449
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??? Here's my test code - I'm trying to inheriting the textbox, so when I place it on my form, I want the backcolor of the texbbox to change to yellow....
25
2589
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 constants in Python language. There are some workarounds available, for example the const-module. To me, this looks quite cumbersome and very unintuitive. For the interpreter, in the efficiency-wise, I just cannot tell.
3
2354
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 Constants'.
33
5578
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 practically a red-black tree where insert/delete takes O(lg n) time. Or are there some other explanation for this complexity?
18
1932
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
2814
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 naming names here to remove bias - I'm trying to tell if I'm relying on implementation defined behavior or if this is a bug in the new compiler. Consider this stripped down example:
0
9551
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10504
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10274
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10251
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7576
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6811
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.