We start with Microsoft's . NET guidelines: msdn.microsoft.com/en-us/library/ms22904... (link updated for . NET 4) Microsoft's C# guidelines: blogs.msdn.com/brada/articles/361363.asp... then document the differences from and additions to that baseline.
IDesign has a C# coding standards document that is commonly used. Also see the Framework Design Guidelines 2nd Ed.
Ironically setting the actual standards are likely to be the easy part. My first suggestion would be to elicit suggestions from the other engineers about what they feel should be covered, and what guidelines they feel are important. Enforcing any kind of guidelines requires a degree of buy-in from people.
If you suddenly drop a document on them that specifies how to write code you'll encounter resistance, whether you're the most junior or senior guy. After you have a set of proposals then send them out to the team for feedback and review. Again, get people to all buy into them.
There may already be informal coding practices that are adopted (e. G prefixing member variables, camelcase function names). If this exists, and most code conforms to it, then it will pay to formalize its use.
Adopting a contrary standard is going to cause more grief than it's worth, even if it's something generally recommended. It's also worth considering refactoring existing code to meet the new coding-standards. This can seem like a waste of time, but having code that does not meet the standards can be counter-productive as you will have a mish-mash of different styles.It also leaves people in a dilemma whether code in a certain module should conform to the new standard or follow the existing code style.
I have always used Juval Lowy's pdf as a reference when doing coding standards / best practices internally. It follows very close to FxCop/Source Analysis, which is another invaluable tool to make sure that the standard is being followed. Between these tools and references, you should be able to come up with a nice standard that all your developers won't mind following and be able to enforce them.
The other posters have pointed you at the baseline, all I would add is make your document short, sweet, and to the point, employing a heavy dose of Strunk and White to distinguish the "must haves" from the "it would be nice ifs". The problem with coding standards documents is that nobody really reads them like they should, and when they do read them, they don't follow them. The likelihood of such a document being read and followed varies inversely with its length.
I agree FxCop is a good tool but too much of this can take all the fun right out of programming, so be careful.
Never write your own coding standards use the MS ones (or the Sun ones or ... as appropriate for your language). The clue is in the word standard, the world would be a much easier place to code in if each organization hadn't decided to write their own. Who really thinks learning a new set of 'standards' each time you change teams/projects/roles is a good use of anyone's time.
The most you should ever do is summarize the critical points but I'd advise against doing even that because what is critical varies from person to person. Two other points I'd like to make on coding standards Close is good enough - Changing code to follow coding standards to the letter is a waste of time as long as the code is close enough. If you're changing code you didn't write follow the 'local coding standards', i.e.
Make your new code look like the surrounding code. These two points are the reality to my wish that everybody would write code that looked the same.
I found the following documentation very helpful and concise. It comes from the idesign.net site and it is authored by Juval Lowy C# Coding Standard.
I would be tempted to enforce Microsoft's StyleCop as the standard. It can be enforced at the build time. But if you have legacy code then just enforce using StyleCop on new code.
code.msdn.microsoft.com/sourceanalysis Eventually it will have a refactor option to cleanup code. blogs.msdn.com/sourceanalysis.
2 You may not agree with everything enforced by StyleCop, but consider that Microsoft are moving towards a single standard, as enforced by StyleCop - so this is a set of standards you can expect other developers to be familiar with. Consistency with much of the rest of the industry could be valuable. – Bevan Nov 22 '08 at 4:15.
I would add Code Complete 2 to the list (I know Jeff is kind of a fan here)... if you are a junior developer the book comes handy to setup your mind in a way that sets the foundation in your mind for the best code writing practices and software building there is. I got to say that I came a bit late in my carreer to it, but it rules a lot of the ways I think about coding and framework development in my professional life. Worth check it out ;).
I was about to suggest the same book. A must read. – Pascal Paradis Nov 28 '08 at 13:48.
Microsoft's own rules are an excellent starting point. You can enforce them with FxCop.
Personally I like the one that IDesign has put together. But that's not why I'm posting... The tricky bit at my company was taking all the different languages into account. And I know my company isn't alone on this.
We use C#, C, assembly (we make devices), SQL, XAML, etc. Although there will be some similarities in standards, each is usually handled differently. Also, I believe that higher level standards have a greater impact on the quality of the final product. For example: how and when to use comments, when exceptions are mandatory (e.g. User initiated events), whether (or when) to use exceptions vs. return values, what is the objective way to determine what should be controller code vs presentation code, etc. Don't get me wrong, low level standards are also needed (formatting is important to readability!) I just have a bias towards overall structure.
Another piece to keep in mind is buy-in and enforcement. Coding standards are great. But if nobody agrees with them and (probably more importantly) no one enforces them then it's all for naught.
I've just started at a place where the coding standards mandate the use of m_ for member variables, p_ for parameters and prefixes for types, such as 'str' for strings. So, you might have something like this jouer au site de casinos virtuels in the body of a method: m_strName = p_strName; Horrible. Really horrible.
1 IntelliSense in Visual Studio 2010 lets you type "Name" and it will match the substring in p_strName - makes it 10% less painful when you're forced to work with such an abomination. :o – 280Z28 Dec 12 '09 at 21:33 indeed, horrible abomination! – Gustavo Cavalcanti Oct 21 at 0:11.
Why not use . NET standards? irritatedvowel.com/Programming/Standards....
You are most likely being set up to fail. Welcome to the industry. I disagree - so long as he creates the document, the worst that can happen is that it gets forgotten by everyone.
If other people have issues with the content, then you can ask them to update it to show what they'd prefer. That way it's off your plate, and the others have the responsibility to justify their changes.
I disagree. The worst that can happen is that the guidelines are inconsistant; and bugs slip by. If he happens to be writing control software for the LHC, then we're f'd.
/Sarcasm – TraumaPony Sep 22 '08 at 4:37.
I have recently found Encodo C# Handbook, which includes ideas from many other sources (IDesign, Philips, MSDN). Another source may be Professional C#/VB . NET Coding Guidelines.
I'm a big fan of the Francesco Balena book "Practical Guidelines and Best Practices for VB and C# Developers". It's very detailed and covers all the essential topics, It doesn't just give you the rule, but also explains the reason behind the rule, and even provides an anti-rule where there could be two opposing best practices. The only downside is that it was written for .
NET 1.1 developers.
Our entire coding standard reads roughly, "Use StyleCop.
Excellent resource, thanks! – TK. Nov 30 '08 at 12:29 The link is broken now.
– ydobonmai Sep 7 '10 at 12:05.
I have to suggest the dotnetspider.com document. It is a great and detailed document that is useful anywhere.
I think I echo the other comments here that the MS guidlines already linked are an excellent starting point. I model my code largely on those. Which is interesting because my manager has told me in the past that he is not too keen on them :D You have a fun task ahead of you my friend.
Best of luck, and please ask if you need anything more :).
The standard from Philips Medical Systems is well written, and mostly follows Microsoft guidelines: tiobe.com/content/paperinfo/gemrcsharpcs... My standards are based on this with a few tweaks, and some updates for . NET 2.0 (the Philips standard is written for . NET 1.
X so is a bit dated).
I've used Juval's before and that's through if not overkill, but I'm lazy and now just conform to the will of Resharper.
I also follow Resharper. Also the guide line mentioned on scott guthrie blog weblogs.asp.net/scottgu/archive/2007/10/... And csharpguidelines.codeplex.com/releases/v....
In the code I write I usually follow . NET Framework Design Guidelines for publicly exposed APIs and Mono Coding Guidelines for private member casing and indentation. Mono is an open source implementation of .
NET, and I think those guys know their business. I hate how Microsoft code wastes space: try { if (condition) { Something(new delegate { SomeCall(a, b); }); } else { SomethingElse(); Foobar(foo, bar); } } catch (Exception ex) { Console. WriteLine("Okay, you got me"); } What you might find strange in Mono guidelines, is that they use 8-space tabs.
However, after some practice, I found that it actually helps me writing less tangled code by enforcing a kind of indentation limit. I also love how they put a space before opening parenthesis. Try { if (condition) { Something (new delegate { SomeCall (a, b); }); } else { SomethingElse (); Foobar (foo, bar); } } catch (Exception ex) { Console.
WriteLine ("Okay, you got me"); } But please, don't enforce anything like that if your coworkers dislike it (unless you are willing to contribute to Mono ;-).
You can check out this,Top 7 Coding Standards & Guideline Documents For C#/. NET Developers amazedsaint.com/2010/11/top-6-coding-sta... hope this helps.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.