views:

96

answers:

7

Possible Duplicate:
C# Coding standard / Best practices

What VB.NET or C# coding standards are 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

+2  A: 

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

bechbd
How does it make your code act like the CLR? Did you just make that up?
klausbyskov
@klausbyskov I'm guessing that bechbd meant to say seem the same, or feel the same.
Conrad Frix
Yeah sorry I meant that following the same naming standards as the CLR makes your code have the same feel as the CLR. Thanks for the assist Conrad.
bechbd
@bechbd, that *should* be, "following the same coding standards as the **BCL**, not the CLR.
Kirk Woll
Sorry, you are correct Kirk it should be BCL. My bad.
bechbd
A: 

Don't use hungarian notation. It is a relic, and has no place in an object oriented language.

Oded
Hungarian notation still has some uses, for instance you could use dirty and clean prefixes to represent data before and after validation so there is never any confusion about what you are dealing with. I 150% agree though that prefixing the type is not the right thing to do, ever.
Matthew Vines
+1. That does not deserve a downvote IMO.
klausbyskov
Can the downvote please explain? If you disagree, please add your thoughts.
Oded
A: 

Check this post for c#

JSC
+1  A: 

I would recommend StyleCop for coding standards.

Vadim
A: 

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.

drventure
A: 

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.

klabranche
+1  A: 

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:

  1. Guidelines for Names;
  2. C# Reference;
  3. General Naming Conventions.

Hope this helps! =)

Will Marcouiller