Solved

A Quest of Style

Posted on 2004-08-24
11
274 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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

762 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

20 Experts available now in Live!

Get 1:1 Help Now