Solved

A Quest of Style

Posted on 2004-08-24
11
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.

733 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