Coding standards for VB.NET [duplicate]
Possible Duplicate:
C# Coding standard / Best practices
What VB.NET or C# coding standards ar开发者_StackOverflow中文版e you using for your .NET applications?
I was looking at hungarian notation and I don't think it is a good idea for a .NET application.
Any suggestions?
Thanks
I'd suggest following the ones provided by Microsoft if possible. It should make your code and the CLR seem the same.
General Naming Conventions
Don't use hungarian notation. It is a relic, and has no place in an object oriented language.
I would recommend StyleCop for coding standards.
There are a few convention rules to follow. Here are some simple examples:
Private members (fields)
They are often seen to start with an underscore character, or the small 'm' letter followed by an underscore.
C#
private string _customerName;
private string m_CustomerName;
Visual Basic
Private _customerName As String
Private m_CustomerName As String
The most frequently used approach, is the single underscore charater as pictured in the first line of each C# and VBNET examples.
Methods (always capitalized)
Name of methods, by opposition to Java to give an accurate example, are always capitalized:
Java
public string getString() { }
.NET (both C# and VB)
public string GetString() { } // C#
Public Function GetString() As String ' VB
Interfaces
Interfaces always start with a capitalized I
.
public interface ICustomer { }
Public Interface ICustomer
And Interface
Attributes
Attribute classes are meant to end with the word Attribute
.
public class MyClassAttributeAttribute { }
Public Class MyClassAttributeAttribute
End Class
Here are some links that may help you dig it deeper:
- Guidelines for Names;
- C# Reference;
- General Naming Conventions.
Hope this helps! =)
A really good reference for .net coding standards
http://www.amazon.com/Framework-Design-Guidelines-Conventions-Libraries/dp/0321545613
I don't agree with all of their suggestions, but it's a good (and complete) starting place.
Hungarian is definitely bad in .net UNLESS you're working extensively with pinvoke and direct Win32 api calls, in which case I continue to use it because so much of the sample code and documentation does.
One thing I tend to subscribe to with coding standards is "The fewer the better"
Generally, if they all can't fit on a single front sided sheet of paper, you've likely got more "standards" than any of you're devs will ever bother with.
Use someone elses hard work in creating standards instead of creating your own like the All-In-One Code Framework.
http://1code.codeplex.com/
My team once went down this rabbit hole and for weeks on end we met trying to standardize every little thing and then found we were wore out and had to consider doing it again when the environments/language changed.
No need to reinvent the wheel. The All-In-One Code Framework has explanations, samples in VB.Net, C#, C++ and is open source and has been reasonably kept up to date.
精彩评论