The blog of Eric Sibly; focusing on mountain biking, .NET development for the Desktop, Smartphone and PocketPC.

Wednesday, April 20, 2005

Coding guidelines...

I am still amazed at the number of people who are coding in .NET who still do not understand the basic coding guidelines. For example, when to use a properties, when to use camelCase versus PascalCase, how to handle exceptions, etc. So if you're not sure, visit here for a quick refresher. Also, I would suggest subscribing to Brad Abrams blog where a wealth of fantastic information regarding this subject awaits you :-)

Also, for all those developers out there - consider visibility - in when to expose as public, protected, internal and private, whether to support overrides, whether to make a class abstract, etc. These all ensure that the code you author is used properly and not abused by consuming developers (typically accidentally) by ensuring members can not be used where inappropriate. So, consider whether you want to allow a type to be instantiated outside of the owning assembly, whether a type can and should allow for inheritance; and whether a method or property can be overridden (if in doubt, don't!).

And finally, for all your public and protected members *please* remember to validate. Check for nulls and check for invalid ranges and throw ArgumentNullException's and ArgumentException's. This is preferred to assuming you will get passed valid data and then getting a runtime exception; i.e. when you attempt to access a property of a type and get a resulting NullReferenceException. In my opinion these are pure evil and are the result of lazy programming. So validate and save your consuming developers hours of debugging by throwing bad data right back at them!

There concludes another rant - have a nice day ;-)


Post a Comment

<< Home