Coding Standards for C#?
infinite9 asks: "I've been given the task of writing the coding standards for my corporation. I've been in IT for 12 years, so many things are obvious. Recently though, my employer has standardized on C# and .NET, and since I'm new to the technology (isn't everyone?) I'm not sure what to include. I've included a paragraph about signing assemblies with a standard key pair as well as a few other odds and ends. Apart from the obvious statements that apply to any language like good comments, good variable names, and maintainable code, can anyone suggest other C#/.NET related things that I should include?"
Don't attempt to come up with any of your own formatting rules (as much as it's tempting to make your code look like the rest of your code)... having a standard formatting implemented by the IDE results in much cleaner formatting and will ensure that the people you hire will understand the code that much sooner.
To work out some standards use what you know from Java, Python or any other language with a C based syntax.
The guys at ICSharpCode (http://www.icsharpcode.net/TechNotes/) have some nice documents on coding styles/standards for coding for #Develop (you don't have to follow them when coding using #Develop)
Also have a look at something like FX Cop from MS (http://www.gotdotnet.com/team/libraries) to help enforce coding standards.
t
I would also stress: use the inline documentation stuff a log (/// comments). Use NDOC to generate documents from the XML output. Make use of the using() {} statement to encourage early resource disposal.
It doesn't really matter what coding standards you implement, as long as something consistent is used. And that doesn't really matter much either.
Microsoft will probably innovate a new language syntax soon, my guess would be C##. It will undoubtedly be more scalable, secure, robust and less prone to errors. And it'll automatically be included in the latest version of Windows, but not be compatible with previous versions due to architecture limitations.
Personally, I'm holding out for that version. I'm going to push my company to standardize on that version. Because it just makes good business sense.
We need a moderation for Sarcastic!
Maybe you'll find this useful: White paper on resource management in components written for the Common Language Runtime (CLR).
-jk
> and since I'm new to the technology (isn't everyone?)
;-)
Used Java?
Make sure you recommend CVS, or some other type
of versioning system to save hell down the road.
Enforce under penalty of death or termination of
employment that DOCUMENTATION IS PART OF DEVELOPMENT.
I've had many a contract where I've basically just
had to say "screw it" and redo a rats nest of
undocumentated code because of zero documentation.
For every annoying gentoo user, are three even more annoying anti-gentoo crybabies. Take Yosh from #Gimp for example.
....several other readers. Take a look at FxCop.
It will help you check your code for conformance to design guidelines and point out possible usage errors, localization issues, security problems, and possible performance improvements.
Recently though, my employer has standardized on C# and .NET, and since I'm new to the technology (isn't everyone?)
.NET now is like adopting J2EE when it was at version 1.0 or 1.1. The details of the APIs aren't hammered out, yet, so a lot of code your company creates will be "legacy" very quickly--probably within one year. If you don't believe me, ask anyone who jumped onto the JSP and Java Servlet bandwagon when they first came out (before tag libraries, etc.).
I'm suprised your company would take such a high-risk action. "Standardizing" on something so new and untested is, IMO, irresponsible.
Adopting
Healthcare article at Kuro5hin