Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Coding Standards or Guidelines

Hi all,

I've read the discussions here about Hungarian notation and also Microsoft's guide to writing libraries ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpgenref/html/cpconnetframeworkdesignguidelines.asp ) but I wonder if anyone has any (official hopefully but even home-grown) coding guidelines like the Sun ones for Java.  Things like where to put the using statements in relation to the namespace statements and curly brace style (I gather from AutoCorrect in Visual Studio that this one is yet another deliberate petty difference from Java).

Does such a thing exist or are the "Design Guidelines for Class Library Developers" all we have?

Thomas David Baker
Monday, June 23, 2003

Why in god's name do you want people telling you where to put your curly braces???

Brad Wilson (dotnetguy.techieswithcats.com)
Monday, June 23, 2003

Yes! I use the coding style pioneered by Kerninghan & Richie in their "The C Programming Language" book.

:-)

John Conveyor (another russian)
Monday, June 23, 2003

I want my curly brace style defined because its more important to have a standard than what the standard is.  The day Sun decided to define which curly brace should be used with Java was a glorious day - end of all arguments from other perspectives as far as our team were concerned.

Anyway, I'm not really after directives on curly brace style but on everything - file naming conventions, where to put copyright text, which of the XML attributes are required and which are optional in comments, indentation style, etc. etc. just like these great argument-ending decisions from Sun: http://java.sun.com/docs/codeconv/html/CodeConvTOC.doc.html

Of course curly brace style is not important but its better to have a doc to point at when you're telling someone who wants to do it a different way.  I want YOU to be able to pick up my code and run with it long after I'm done with it.  I want my code to be idiomatic, to be indistinguishable from example code from Microsoft (the good examples, that is).  AND I want a document with it all in I can point fellow developers at.

Does such a thing exist?

Thomas David Baker
Tuesday, June 24, 2003

The only thing I've seen is the class library guidelines that you already mentioned. Historically, Microsoft hasn't been much interested in promoting coding guidelines.

Mike Gunderloy
Tuesday, June 24, 2003

http://www.icsharpcode.net/TechNotes/SharpDevelopCodingStyle03.pdf

That's a decent guideline, I suppose.  I guess you'd like section 10.1, though everyone has their preference.

Ryan Duffield
Wednesday, June 25, 2003

Let's not get hung up on curly braces here!  Its EVERYTHING that I need defined not curly braces in particular.

That said, I can't use the standards in the PDF because it has a different curly brace standard than Visual Studio 2003.  Its really Microsoft that needs to publish standards - any other source (for .Net) will be ignored I think.

The class library designer's ones are perfect as far as they go (naming guidelines, exception use, etc.) I just wish they went one level of detail further or an additional section detailed "preferred layout" and that kind of thing.

Thomas David Baker
Thursday, June 26, 2003

Thomas: I believe you have already answered your own question:

"... its more important to have a standard than what the standard is."

You're absolutely right--it doesn't matter so much what your coding standard is, as well as it's:

1. Easily readable
2. Understandable by everyone on your team
3. Includes PDL
4. Follows a consistent naming and layout style.

For naming suggestions and general construction guidelines, pick up a copy of Code Complete by Steve McConnell.  He covers those topics in great detail.  How to name routines, use of PDL, loose coupling, tight cohesion.

I'd start there,  If you'd like, I can e-mail you our coding standard for C# to get you set off in the right direction.  It's based on about 30 combined years of professional coding...

Dave
Friday, June 27, 2003

Wow.  I could stand to read my posts before submission.  Today was a long day and apparently, my prose is suffering...

Dave
Friday, June 27, 2003

Sorry everyone I'm obviously not being very clear.

I'm not talking about just having a standard.  Obviously we will have a standard.

What I want when picking that standard is to be maximally compatible with the standards that other people have chosen.

Let's use curly braces as an example (but I'm talking about everything here):

I use K&R style (new line for functions, same line for control statements) when coding C because its in K&R which is the main place people learn C.

I use always-on-the-same-line style when writing Java because its in the Java coding guidelines.

I use always-new-line style when writing c# because that's what Visual Studio enforces by default and that's where most people will write their c#.

What I'm saying is that I want to get in the habit of writing code to standards that are not only applicable in my workplace but also out there in the wide world so that if I (say) wanted to contribute to an open source project I'd have the least possible work to do to adapt my standards to theirs.

To this end I would like some standards from M$ just like we have from Sun for Java (not that everyone follows them but they ARE the most commonly followed standard).  Visual Studio's defaults are a clear hint (tabs not spaces, new-line curly brace, etc.) but I'd rather have a document.  I have come to the conclusion that the library-writers-guide is the only thing out there at the moment though.

Thomas David Baker
Wednesday, July 09, 2003

*  Recent Topics

*  Fog Creek Home