Lance's Whiteboard

Random scribbling about C#, Javascript, Web Development, Architecture, and anything else that pops into my mind.

News


Creative Commons License
Lance's Whiteboard Blog by Lance Hunt is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Based on a work at weblogs.asp.net




Sponsored Ad
Sponsored Ad

Blogs I Read

C# Coding Standards

I recently started documenting my own C# Coding Standards and best practices.   The current document is very much a work-in-progress, but I am making it freely available for download.  Please reply with any comments, questions, or feedback on this blog entry.

Click Here, to download the PDF.
[ Updated to v1.13a]

 

Why yet another coding standard document?

There have been numerous attempts at document C# Coding Standards since the language was released, but I usually have disagreements with many of the guidelines and rules they contain.  This is my attempt to start from scratch and write a new standards document that represents my preferred style.  I'm sure that many of you will have just as many disagreements, but I am looking forward to the debate. :)

Enjoy!

 

Comments

Wes said:

For the most part I agree with most of your standards. There are two things I noticed that I do differently. I use all uppercase for constant names and I don't use "_" for member variables instead I always prefix with the keyword "this". I don't know if you care but I also noticed you used both the words function and method, I find myself doing this too but when I realize it I switch it to method.

HTH
Wes
# May 9, 2004 1:14 PM

Lance said:

Thanks for the feedback...

I think you hit on all of the areas that I see the most debate.

I am still undecided on using uppercase names for Constants. I have to admit that I occasionally switch between Uppercase and treating them like member variables depending on the project.

I fixed the references to function vs. method. Thanks for the catch!

I just posted an updated version (v1.01) with various additions, changes, and the correction above.

Let me know what you think...
# May 9, 2004 2:33 PM

James said:

Why do you recommend creating strongly typed datasets?
# May 9, 2004 4:39 PM

AndrewSeven said:

I had a brief look, seems mostly ok.

How about a creating a set of rules for fxCop, so we can see what the rules haev to say about some code.
# May 10, 2004 9:19 AM

Lance said:

James,

Strongly typed datasets give 2 advantages;
Tables, rows, and columns are exposed as strongly typed object properties (intellisense!), and improved performance due to design time type checking. Also, they are just so darn easy to create in VisualStudio.NET, that there is no real reason not to unless your data-source, tables, and columns change frequently at runtime.



AndrewSeven,

Great suggestion! I have an older FxCop configuration, but need to update it. I'll see what I can do.


Thanks for the feedback guys!

# May 10, 2004 11:24 AM

TrackBack said:

# May 10, 2004 8:18 PM

TrackBack said:

# May 10, 2004 10:57 PM

anonymous method said:

public Collection<Order> Orders
{
get
{
...
}
}

public Collection<Status> XX
{
get
{
...
}
}

So by your coding standards what would you name property XX?
# May 12, 2004 6:30 PM

Lance said:

Both properties should be changed to append Collection as a suffix to the underlying type.

Since the return value is a Generic Collections of a particular type, call them by the Generic Type name followed by "Collection" just like in a strongly typed collection.

E.g. OrderCollection & StatusCollection

Enjoy...

P.S. Yeah, I realize you were just playin me, since the plural of Status is Status. I have been known to rename such a property just to avoid the naming dilemma. :)
# May 12, 2004 11:34 PM

TrackBack said:

# May 20, 2004 12:31 PM

TrackBack said:

# May 20, 2004 12:42 PM

TrackBack said:

# May 20, 2004 12:43 PM

MG2 said:

I've always used "States" as the plural of status. It may or may not be dictionary-proper, but it gets the point across. If you really want to eliminate the confusion, you can then change the single "Status" to "State" since most times they are functionally equivalent.
# May 27, 2004 1:44 PM