The Design of Software (CLOSED)

A public forum for discussing the design of software, from the user interface to the code architecture. Now closed.

The "Design of Software" discussion group has been merged with the main Joel on Software discussion group.

The archives will remain online indefinitely.

C# Coding Conventions

Can somebody please point me to a good set of C# Coding Conventions? I realize "good" in this case is highly subjective, but I don't want to reinvent something that has already been done "well enough".

Thanks!
Roger Jack Send private email
Sunday, January 30, 2005
 
 
Hi Roger,

there is a "C# Coding Style Guide" written by Mike Krueger, one of the developers of SharpDevelop. It should be a good starting point. You can download the PDF from their web site: http://www.icsharpcode.net/TechNotes/

MSDN also offers some guidance on this subject: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconnamingguidelines.asp

Good luck!
Neven Zovko Send private email
Sunday, January 30, 2005
 
 
There aren't any uniform coding conventions for C#, not even at Microsoft internally. (They don't all follow their own guidelines...) Basically, use your favorite C or Java style.
Chris Nahr Send private email
Monday, January 31, 2005
 
 
This is my favourite, because it fits one page: http://www.irritatedvowel.com/Programming/Standards.aspx

You might also like to check out these interal guidelines, just released by MS: http://blogs.msdn.com/brada/articles/361363.aspx

Finally, there's FxCop.  I've yet to use it "in anger", but you may find it useful, particularly if your team is writing libraries for consumption by other teams/companies.
John Rusk Send private email
Monday, January 31, 2005
 
 
I love the way Brad Abrams waxes lyrical about not prefixing private members, then points people to the SSCLI as an example of good code, where half of his golden rules are solidly broken.

Face it, folks - underscore it where it's at :-)
.NET Guy
Monday, January 31, 2005
 
 
Mark Kreuger's style keeps the 'curly at the end of the line' and 'use Tabs for indenting' school of thought, both of which I disagree with more or less violently.

The Blog entry is good however:
DON'T use tabs (they always format differently on different platforms/different tab settings) and
Put open curly's on their own line, so their indentation clearly shows code blocks.

It's interesting that two 'C#' "standards" could recommend exactly opposite behavior -- but that's why we have standards, I suppose.
AllanL5
Monday, January 31, 2005
 
 
"no tabs" is interesting, my take-home lesson from the tab problem was that indentation is for indentation and not lining stuff up. And because lining stuff up requires you know the indentation, you shouldn't line stuff up. (It distracts the eye, too.)

Write your code like this, and you can have tabs set to whatever -- it still looks fine.
Tom_
Monday, January 31, 2005
 
 
"Lining stuff up" as you put it is SUPPOSED to distract the eye.  Rather, it's supposed to FOCUS your attention on blocks of things that belong together.

That's what indentations do -- or that's what they're supposed to do.  It's then up to the developer to make meaningful blocks.

That's the nice thing about using spaces for indentations -- the lining up then stays, no matter what your tab settings are.
AllanL5
Monday, January 31, 2005
 
 
Until some idiot goes and insists on reading your code with a proportional font.

But it's not till they start trying to insist YOU read it with a proportional font that tabs start looking awfully attractive again...
It happens. Really.
Wednesday, February 02, 2005
 
 
Oh, yeah, and I thought that went almost without saying, but apparently not, so here goes:

Only read code in a non-proportional (aka fixed) font.

Proportional fonts are for documents, not code.

Code has the capacity of leaving out much of the needed design information.  Properly indenting code blocks and arrangeing layout on the page allow you to at least indicate what clumps of code implement design elements.  Viewing this in a proportional font removes much of this value.
AllanL5
Wednesday, February 02, 2005
 
 
People like to read code, like anything else, in proportional fonts because things are more readable that way.  Proportional fonts are designed for reading; non-proportional fonts are not.  Why do you think people don't like reading your code?

This is the only thing I'm aware of non-proportional fonts being useful for:

http://www.asciimation.co.nz/
Kyralessa Send private email
Wednesday, February 02, 2005
 
 
Kyralessa, why do you keep contradicting me with true-isms that you then don't prove?

"People like to read proportional fonts" does not address either of the reasons I gave as to why you should not read code in proportional fonts.  I'm a people, and I dispise proportional fonts in code, for the reason's I gave above.

Yes, when I'm reading Science Fiction, I like it to be in a proportional font.  When I'm reading C++, Java, or Visual Basic, I like it to be in a fixed font.

I'm happy that in your world, all people like proportional fonts.
AllanL5
Wednesday, February 02, 2005
 
 
I'm contradicting you because you're putting forth ironclad rules about things that are really a matter of preference.  People who do that annoy me.  :P
Kyralessa Send private email
Wednesday, February 02, 2005
 
 
(But why do you say "keep contradicting"?  Have I done this often?)
Kyralessa Send private email
Wednesday, February 02, 2005
 
 
Fair enough, I'll look to my words.  Thanks.

And yes, there was one other occasion you objected to my words.  Since we tend to agree on stuff, I was surprised at the time.  Now it has happened again, and I see I was being "categorical" as they say.  Good to know.
AllanL5
Wednesday, February 02, 2005
 
 
Darn you, AllanL5!  You said that just so I'd waste time searching for the other one, didn't you?

I couldn't find it.  But anyway, if it was in Off Topic, it doesn't count.  :)
Kyralessa Send private email
Wednesday, February 02, 2005
 
 

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics
 
Powered by FogBugz