C# Coding Standards

By fango256

I’m not quite sure why, but recently I have been really chomping at the bit about C# coding standards.   Maybe it’s because of the very good Framework Design Guidelines book by Brad Abrams et al which I have just finished reading.  This book does a great job in telling you what you should be doing and why. Ordinarily this would soon get on my nerves, but the authors of this book have dotted around little anecdotes and technical commentary which explain the reasons in a really human (some emotions are involved) kind of way.  This makes the book far more readable than you might think.

If you don’t want to shell out for the book or you think emotions are overrated then the information is pretty much available on MSDN: Design Guidelines for Developing Class Libraries

The major two points that stuck out for me:

Scenario Driven Design

The book hammers home the importance of first understanding how your code is going to be used.  It really makes sense, there’s little or no point in writing a beautiful framework if its usage has not been thought about in the context of the end user.

Scenario1: Accelerate a car then stop it.

Car myCar = new Car();

myCar.Accelerate(100);

myCar.Stop();

Scenario2: etc…

Simple Yet Powerful

One mistake I often fall into is making my code too powerful (read complex).  The book described the importance of your user being able to solve 80% of their problems with simple code.  For example the System.IO.File class accomplishes most of the users requirements in regards to file i/o but in the rare occasion where more power is needed then you have FileStream for all the stream operations to help you.  A very good point indeed.

Leave a Reply