C# Coding Standards
Download Lance's C# Coding Standards v1.1.5
I started my C# Coding Standards document back in the early days of .NET and C#. The very first incarnation was for my employer in response to an incoherant mess created by a dozen developers who coded to their own drumbeat. We sought agreement on everything starting from tabs vs spaces, curly braces, and naming conventions. I made a first stab at a document, and it was quickly ratified as our standard with only a few tweaks - everyone was pleased and started making their code 100% match the standards. Note: it was quite a tome! Over 12-pages long, guaranteeing that outside of this one effort nobody would ever read it again, let alone follow its "wisdom".
As my understanding and usage of C# evolved, I became ever dissatisfied by the result of my first endeavor and made attempts to revise the coding standards and further evolve it. Unfortunately, adoption of these changes was was met with resistance as the committee who approved the document was satisfied and saw further revisions unneccessary - thus it became etched-in-stone. Beyond the oppressive girth of the document, I considered the end result a complete failure because coding standards should be an ever-living and growing entity that reflects your team's evolving perception of best practices over time, not a paperweight to burdon the desks and inboxes of developers. As a result, I decided to start my own coding standards and share it with the world.
This document (or its earlier naieve incarnation) is the result of that rebellion against immutable C# Coding Standards. Its primary goal was to come up with a concise set of guidelines that could be quickly consumed as either a reference or a quick read-through. I continued to tweak and revise for several years until apathy, work, and family needs overcame my ability to maintain it further.
Since then my document has been adopted, translated, and used as the inspiration for thousands of teams' coding standards all over the world. For that, I am forever flattered. Ironically, because I stopped publishing my C# Coding Standards in 2007, I fear that now I have created a bigger problem - yet another non-evolving coding standard. For the many people who have been oppressed due to my document's inertia - I am forever sorry.
Today I feel that coding standards are enforced excessively and that a more minimalistic approach to coding standards is more appropriate for most teams. However, until I decide to revise this document yet again, or help those who want a baseline from which to evolve their own coding standard, I preserve here, my last known good version of my C# Coding Standards document for those still interested in using it as an inspiration for their own teams - please use it only as a starting point from which you can evolve your own standards.
Thank you.
Lance Hunt
Release Notes:
- Added numeric datatype usage guidelines.
- Adjusted guidelines for public, protected, and internal access modifiers.
- Tweaked verbage throughout document.
- Modified layout & added License Agreement. Misc. grammar adjustments.
- Removed rules on foreach vs for pending additional research.
- Added rules on switch/case statements.
- Revision(a) recommends custom Exceptions to subclass Exception not ApplicationException
- Modified code commenting and formatting rules.
- Modified various code examples.
- Modified Exception Handling and Flow Control sections.
- Modified formatting.
- Restructured “Language Usage” section.
- Corrected language, and added code examples.
- Consolidated conflicting rules.
- Modified naming conventions for Internal and Protected identifiers.
- Added, modified, & removed misc rules.
- Corrected grammar, code, and some verbiage.
- Changed style & formatting.
- Added Quick Summary tables.
- Added/modified various standards.
- Split .NET guidelines into separate document.
- Changed overall scope and goals. Restructured sections. Improved Introduction.
- Added Scope and Terminology sections.
- Added Bibliography, Resources, and .NET Framework Guidelines.
- Misc. adjustments to various rules.
- Updated Naming Conventions.
- Misc. grammar and syntax changes.
- Changed formatting and organization.
- Added code examples.
- Added more Language Usage.
- Created