Solved

A Quest of Style

Posted on 2004-08-24
11
276 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
New to SOAP and need some direction 10 83
System.Speech 2 28
Simple Injector with Web Service 4 41
Where did System.Data.Objects go? 2 28
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

809 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