Solved

A Quest of Style

Posted on 2004-08-24
11
275 Views
Last Modified: 2010-04-15
Hi,

i am starting to do some serious programming in C# and am wondering about standards for coding. I have read numerious tutorials and papers about various aspect of C# and no two seem to follow a standard. Any i just missing something? I am the only programmer at my work so there are no standards in place to follow.

Question is there anywhere that has set any standards for C# programming in terms of syntax, naming conventions, function positioning in classes, commenting etc.

Or can someone offer some advice.

I know this may seem trival but everything i got taught at uni/work drilled into me about standards. Please Help.
0
Comment
Question by:cossy74
  • 2
  • 2
  • 2
  • +4
11 Comments
 
LVL 3

Expert Comment

by:bigjim2000
ID: 11888825
Here's a convention that much of Microsoft has supposedly adopted, called Hungarian Notation (there is a lot on the web about this):
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnvsgen/html/hunganotat.asp

-Eric
0
 
LVL 15

Assisted Solution

by:Timbo87
Timbo87 earned 100 total points
ID: 11888890
That article is pre-.NET and actually, I believe Microsoft now discourages Hungarian notation in .NET.

Here are Microsoft's .NET Naming Guidelines:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconNamingGuidelines.asp?frame=true
0
 
LVL 3

Expert Comment

by:gillgates
ID: 11888939
It is true that Microsoft discourages Hungarian notation in .NET because the IDE can tell you all about your variables when you do a "mouse over" the variable...  
I still think it is worth using so I do, who want to do a "mouse over" when they could just look at it.
0
 
LVL 8

Assisted Solution

by:gregasm
gregasm earned 200 total points
ID: 11889228
Have you ever heard of FxCop? It enforces coding style and conventions, as well as encapsulating best practices. It has an extensible architecture to allow you to add and enforce your own rules.

You can get FxCop here:
http://www.gotdotnet.com/team/fxcop/

Intro to FxCop here:
http://msdn.microsoft.com/msdnmag/issues/04/06/bugslayer/default.aspx

And here is a great article on how to extend the FxCop rules engine:
http://msdn.microsoft.com/msdnmag/issues/04/09/Bugslayer/
0
 
LVL 4

Assisted Solution

by:somnatic
somnatic earned 100 total points
ID: 11889442
@gillgates ..

this mouse over works without the hungarian notation just as well ..

hungarian notation is from the C age ... with features such as you mentioned there is no need for hungarian notation anymore
I just read an article .. but can't remember where ..


@cossy
the only convention I follow is:
* variableNames start with a lower case letter
* MethodNames start with an upper case letter
* WordsAreSeparatedBy upper case letters
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Expert Comment

by:bigjim2000
ID: 11890066
I do mostly what somnatic does... but I also append b for booleans and i for ints.... it's handy to know which variables are flags, and which numeric variables have a decimal.  Also, I have a convention for naming my controls, like btnButton, and txtTextBox, just so I can tell at a glance what control I'm looking at (in the code).

-Eric
0
 
LVL 3

Expert Comment

by:gillgates
ID: 11896608
@somnatic

 I was saying who wants to do a mouse over when you can just look at it.

I do the following

intVariable
blnVariable
lngVariable
dblVariable
strVariable
btnButton
lblLabel
txtTextBox

I follow similar naming conventions for other variables that I have not listed.
0
 

Author Comment

by:cossy74
ID: 11897731
OK,
thanks for your input.
I understand what is being said.
What about Functions/Methods, Class naming. I followed some Microsoft examples and they list the functions in the code alphabetically, show thius be followed? Do i seperate Data and UI completely?
0
 

Author Comment

by:cossy74
ID: 11897750
Also.

Do i comment functions outside/before or inside the function code.
for example:

/// <summary>
/// Function: PopulateProductList
///
/// Description:
/// Function's purpose, Special Notes etc
/// </summary>
private void Function()
{ }
or

private void Function()
{
/// <summary>
/// Function: PopulateProductList
///
/// Description:
/// Function's purpose, Special Notes etc
/// </summary>
}
0
 
LVL 8

Expert Comment

by:gregasm
ID: 11897885
cossy74, did you take a look at FxCop from the links I posted above?

FxCop is developed in house by microsoft and it is a tool to enforce the best practices, as defined by microsoft. I think it is the best way to learn of and practice c# style.
0
 
LVL 5

Accepted Solution

by:
Kelmen earned 100 total points
ID: 12012893
Since you 1st into the realm of "coding style", advise you simply pick one to kick off.

Just pick the M$ .NET approach.

It take years of experience to grow one's "coding style". It's practically a personal preference/taste/religious stuffs.

While many stated avoid hungarian or FxCop, I still adopted it.

Look from your/company purpose on this styling. Is it mean for biz/sale purpose or practical development?

If for biz/sales/ISO-whatever, adopt a well-know industry standard, of at least from a well known vendor standard (like M$).

If its for practical development purpose, then this will depend on many factors (the senior people over there, what language been adopted in past)

Since you are the 1st and foremost in this part, pick one that suid your taste, mix-and-match some.

Do remember, its "styling", just like fashion, mean you can change/enhance it later on.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Both in life and business – not all partnerships are created equal. Spend 30 short minutes with us to learn:   • Key questions to ask when considering a partnership to accelerate your business into the cloud • Pitfalls and mistakes other partners…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now