Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I stumbled across an article from net.tutsplus.com[^] that was dated a few weeks ago about naming conventions for beginners.

1. Variable names that begin with a capital letter mean that they are a class.
2. Prefixing a variable name with the underscore indicates that the variable is private or protected.
3. ALL CAPS indicate a constant
4. Prefixing a bool variable with "is" (found in anther MS website or programming blog)
5. There are several others that I won't bother to list

I think this is great and it is obvious that I am a beginner... Now, I realize that not everyone follows the rules or guidelines and companies have different coding standards but...

Being a new developer and since there is no one around in the company that I work to enlighten me. I hope someone here can. I am very interested in maintaining some sort of coding standard that would be understood by outside parties if the need should ever arise.

I notice in windows programming, specifically with C#, that sometimes I see code that adheres to the items above and other times it does not.

So... should I name all of my classes with the first character capitalized and use the underscore to denote a private or protected variable? Do I rename all of the controls on a form to follow this practice even though VS2010 does not do this?

Is there a publication of some sort that has become a standard guideline that explains the why and hows of this?

Thanks
Jeff
Posted

Hi Jeff,

Take a look at StyleCop. I think you will find it usefull.

StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project. Provides value by enforcing a common set of style rules for C# code. Developers can implement their own rules if they so choose.
 
Share this answer
 
Comments
Nish Nishant 2-Nov-10 21:32pm    
Voted 5, quality suggestion!
Jeff Patterson 3-Nov-10 10:54am    
This is pretty sweet but OMG what a ton of inconsistencies I have! But the good news is that I have just learned a little more about the XML documentation and how it works. Thanks so much.
As a matter of fact, Microsoft has published a set of design guidelines for the .NET Framework. You can find them online here: http://msdn.microsoft.com/en-us/library/ms229042.aspx[^]

They also exist as a book by Brad Abrams and Krzysztof Cwalina. It's available on Amazon[^] and most other major book retailers.

One thing to bear in mind is that these are guidelines, not hard and fast rules. Follow whatever standards your company has first. Beyond that, do what makes sense for your situation, especially when it comes to names. Using Pascal-casing for class names and underscores for private member variables is generally a good practice. Renaming stuff auto-generated by Visual Studio is not. You'd be spending a lot of time on something with essentially no benefit.
 
Share this answer
 
Comments
Jeff Patterson 3-Nov-10 10:58am    
This is exactly what I was looking for. I really like to understand why and how "rules" were created before I decide to implement them or even break them. At least now I have a logical starting point and a foundation.
Thank You.
there is no why and hows, it is the coding standards set forth just to be able to understand at later part of time and during reuse, It is different for different companies and these are set by the company standards some follow camel casing, caps and several other standards. If you could follow one standard that's ok no need to treat it as a hard and fast rule just to make life easier that's it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900