Coding Standards for C#? 82
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?"
My personal standard: (Score:1, Funny)
Don't.
Google sez... (Score:3, Informative)
Reasonable, my twopennyworth (Score:3, Informative)
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.
MS design guidelines (Score:4, Informative)
Maybe you'll find this useful: White paper [gotdotnet.com] on resource management in components written for the Common Language Runtime (CLR).
-jk
Re:MS design guidelines (Score:3, Interesting)
One of the main ideas behind guidelines is supposed to be that consistency will result in more programmer productivity because the programmer will recognize new aspects more quickly.
The question is: Does the time it takes to learn the guidelines so they are second nature exceed the time saved by avoiding a lookup of a function or having to come up with your own name?
Guidelines are an engineering product just as m
Re:MS design guidelines (Score:1)
RVBA-like conventions in the works (Score:1)
Use the IDE's beautify (Score:3, Insightful)
Re:Use the IDE's beautify (Score:2)
this might be the least worst thing to do, but VS has terrible default formatting. I forget the name of the style, but this is what you get by default:
combine this with the all the toolbars and help viewers that are on by default, and you can effectively read about 4 lines of code at once.
Re:Use the IDE's beautify (Score:3, Informative)
namespace Foo
{
public class Bar
{
void Bar()
{
if (foo)
{
bar(0);
}
else
{
bar(1);
}
}
}
}
Re:Use the IDE's beautify (Score:3, Funny)
Re:Use the IDE's beautify (Score:2)
You should have previewed anyway.
Re:Use the IDE's beautify (Score:1)
Kinda like comments, but worse.
Real men write:
namespace Foo {
public class Bar {
void Bar() {
if (foo) {
bar(0);
} else {
bar(1);
} } } }
If you need more white space between your lines, adjust your font settings, but don't take it out on the brackets.
Re:Use the IDE's beautify (Score:1)
C# Coding Standards (Score:4, Informative)
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
Wait until you see what's on the horizon! (Score:3, Funny)
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!
Would that be a +1 Sarcastic or a -1 Sarcastic? (Score:2)
I've thought about this as well. The problem is would it +1 Sarcastic or -1 Sarcastic? I think it should be something along the lines of +1 Sarcastic(Funny) and -1 Sarcastic(Asshole). Or how about a 0 Sarcastic that just adds "Sarcastic(" and ")" to the original modifier name?
Just a thought.
Re:Would that be a +1 Sarcastic or a -1 Sarcastic? (Score:2)
In my book Sarcastic would always be a +1. I would, however, like a "-1 poster is an idiot" while we're at it. Oh I suppose that's the Friend vs. Foe system.
VS.NET (Score:2)
CTRL+[SPACE] = Type ahead
I used to program C# with UltraEdit before my company could afford VS.NET. VS.NET paid for itself the first day that I used it because it saved me so much time.
If you have the time, I'd highly recommend reading the C [microsoft.com]
Re:VS.NET (Score:3, Interesting)
Of course the problems with this approach is that it's way too easy to use the IDE as a crutch - especially Intellisense. One day you'll be in a situation (like a technical quiz for an interview) where you won'
Re:VS.NET (Score:2)
As far as wizard generated code goes, the (extraordinarily expensive and worth it) Compuware DevPartner Studio often flags wizard code as non-compliant with
Re:VS.NET (Score:2)
I'm curious. Why *do* people like VS.Net, as opposed to say, emacs?
Re:VS.NET (Score:2)
context sensitive help with examples coded in multiple languages.
Intellisense that integrates user code documentation.
Template creation to limit junior programmer usage of pretty/useless widgets
Good macro support
Integrated web load testing tools
Integrated Active Directory support
Integrated database support
Integrated debugger
Forms designer for the gui guys (I
Re:VS.NET (Score:2)
context sensitive help with examples coded in multiple languages.
But so does man, which comes with cygwin.
Intellisense that integrates user code documentation.
Doxygen.
Template creation to limit junior programmer usage of pretty/useless widgets
Dunno exactly what this is.
Good macro support
Hehe. Yup, I think emacs could manage this.
Integrated web load testing tools
Why would you bundle web load testing tools into an IDE, and what's the benefit
Re:VS.NET (Score:3, Informative)
However, unless you have the enti
Re:VS.NET (Score:2)
If I were on an interview and they were asking me such an API-specific question that Intellisense would have helped me answer it, I wouldn't work at that company anyway.
Re:VS.NET (Score:1)
If a programmer does not know the language well enough to write out a class/method, etc. on a whiteboard without reference then who is really doing the programming?
Part of being a progammer is understanding the language so well that you can see what the language is doing "under the covers". If the IDE does all of that for you, then I guess the company should hire monkeys because the IDE is doing all of the work.
Re:VS.NET (Score:2)
Interesting our lead developer who does our interviews generally asks a question like this, and one of the acceptable answers is "I don't know, but that's easy to find in MSDN."
We're much more pragmatic here in the heartland.
VS.Net Web Form Designer is Very, Very Buggy (Score:1)
If you want to wire in custom events for custom controls, or you just like to code your ascx controls in the source view (not the gui designer) then be prepared to have VS.Net intermittently decide to wipe out your event wirings.
Also be prepared to have VS.Net hijack your xml (the aspx or ascx page) formating any time you switch from source editor to gui editor.
Re:VS.Net Web Form Designer is Very, Very Buggy (Score:2)
Re:A few perls of wisdom (Score:1)
I have no idea. I was aiming for funny!
don't write to winForms (Score:1, Interesting)
New technology? (Score:4, Funny)
Used Java?
Maybe it's just me, but ... (Score:1, Informative)
(The fact that he's consulting with Slashdot regarding aspects of his job is kind of a hint.)
Re:Maybe it's just me, but ... (Score:2, Interesting)
Try Microsoft's published standards first (Score:2)
http://msdn.microsoft.com/library/default.asp?url
Don't abuse Using, try doxygen (Score:2, Interesting)
Re:Don't abuse Using, try doxygen (Score:2)
Re:Don't abuse Using, try doxygen (Score:1)
The point I'm making is to stay away from aliases as much as possible (just check out the header to almost all C# code. You'll see using System; at the front of nearly every file. That's just an alias that does not affect bytecode, but makes the code less clear. Regards...
Using (slightly OT) (Score:2)
Re:Don't abuse Using, try doxygen (Score:2)
Actually, VS.NET comes to the rescue here, as well. If you do a Mouse Hover over the object in question, it will give you full namespace information. If you aren't certain of the class hierarchy, simply mouse over the object and VS.NET tells you what you need to know. More questions? Put the cursor over the object, press F1, and you g
Two non-obvious things I'd suggest (Score:4, Insightful)
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.
Re:Two non-obvious things I'd suggest (Score:2)
Nothing but M$ products for them.
VSS I suppose. Make sure you do those backups.
In addition to the standards document, you should make
sure that you'll have the appropriate budget for buying
new dev tools and training every year. I'd also beef up
your end-user support budget, you'll probably need it.
Also make sure that your current products will be well
supported and viable for the next year or so because
you'll be late on delivery of your C# and
Re:Two non-obvious things I'd suggest (Score:2)
Nothing but M$ products for them.
That looks like a nice, standard mis-informed Slashdot post to me.
For Windows, there is CVS NT [cvsnt.org] which works great. Then you can use Igloo [jalindi.com] for IDE integration. Or the even cooler Tortoise CVS [tortoisecvs.org] for explorer integration (an easier to use source control tool I have yet to find).
OR, there is always Subversion [tigris.org] if you don't want CVS. Subversion also has a Tortoise port.
Or, back in the closed source world, Perforce [perforce.com] and I'm sure a handful of others.
Re:Two non-obvious things I'd suggest (Score:2)
Perforce, Subversion, and CVS are all decent solutions, and all tend to have better reliability than VSS. But I've found that most M$ shops stick with M$ solutions for most tasks. If you're stuck with VSS, f
Re:Two non-obvious things I'd suggest (Score:2)
Sure you might have some resistance to anything that isn't VSS, I was just pointing out some alternatives. I was replying to a misinformed post that said VSS was the only option.
Also, there is Vault [sourcegear.com] which looks very promising. It uses SQL Server as it's repository, and SOAP as the transport and is written in .NET.
In addition to the coding standards pointed by... (Score:3, Informative)
....several other readers. Take a look at FxCop [gotdotnet.com].
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.
Wiki Wiki Wiki (Score:2, Insightful)
Take a look at Twiki [twiki.org].
Poor guy. (Score:4, Insightful)
I'm suprised your company would take such a high-risk action. "Standardizing" on something so new and untested is, IMO, irresponsible.
Adopting
Re:Poor guy. (Score:2)
It doesn't really matter how new or untes
Re:Poor guy. (Score:1)
And surprisingly they find them. I wish I knew how to BS so well. I am tired of seeing BS experts get the jobs over me. I don't like dishonesty, but in this dog-eat-dog economy it is a necessity, and I find that I am not good at it due to lack of practice.
Re:Waiting (Score:2)
VB6, COM, MFC,
FxCop (Score:1)
This very useful program is a code analysis tool that checks your
C# FAQ: *vital* coding standards for C# (Score:2, Interesting)
C# Best Practice: Do not use boxing and unboxing [geocities.com]
check it out here:
csharp faq [geocities.com]
almost useless (Score:2)
There is some value in a list of wise warnings, but that's not how this site presents itself, so I'm forced to conclude that it's just another anti-MS propaganda piece.
Since the REAL story about MS is pretty nasty, yet the technology of C# and
One simple suggestion (Score:3, Interesting)
Recommendations are really just suggestions. For instance, the last coding standards I helped to author we recommended that open brackets (the '{' character) be placed at the end of the expression rather than on a separate line. This recommendation was not followed by some, but it really isn't that critical towards code readability. For the record, I actually like putting open brackets on new lines, so that the open & close brackets line up. I did change my practices, but I occasionally forgot, and didn't get yelled at since it was merely a "recommendation".
Guidelines are "rules" to be followed at all times unless there is a really good reason not to. For instance, we had a guideline that instructions should not be divided between lines, and that only one instruction should appear per line. Well, if you have a really long piece of logic, splitting the instruction across two lines makes sense. Conditional expressions (i.e. something of the form of "(ab)? a : b") counted as a single instruction.
Rules must be followed at all times. For instance, one rule we used was no "goto" statements. Pretty simple and obvious.
We found that by having the rules in this form, people that would categorically reject some of the guidelines under different circumstances were more receptive towards the guidelines when presented in this manner. So long as they weren't forced to adopt these "rules" they somehow seemed less ominous. YMMV.
Re:One simple suggestion (Score:1)
Functions/methods should be separated into "functions", which return a value without modifying external values, and "procedures", which do exactly the opposite.
Re:Trolling Trolling Trolling ....Haza (Score:1)
Sort of...
class A {
private int foo;
public void setFoo(int foo) {
this.foo = foo;
}
public int getFoo() {
return this.foo;
}
}
Rather than...
public int setFoo(int foo) {
this.foo = foo;
return this.foo;
}
One simple comment OT but about the comment... (Score:2)
Thoughts on coding standards (Score:2)
I wasn't going to comment on this thread, not being particularly informed on C# itself, but two things have struck me that might be worth mentioning.
meta data (Score:1)
Defing some basic meta-data that should be present.
Say Author, Data, Changes / BUGS , Links to design and test documentation etc...
It should be easy to link any good configuration management software into the meta-data.