Coding Pet Peeves
Any experienced coder has pet peeves when it comes to reading other people's code or writing code. It might be that you don't like regions or that every method should have comments. But here are my two biggest pet peeves when it comes to C#.
Var abuse
WAY too many people are using var instead of a type. This might save your hand, but it doesn't do much for readability of your code. Don't get me wrong, it is VERY usefully at times. But only about 10% of var use is actually productive. The rest is just abuse!
Angle Bracket Abuse
Yes, we all know that C# has angle brackets, get over it :). If you have one statement inside of an if, while, do, for, foreach, or using, you DON'T NEED ANGLE BRACKETS! Take the following code sample I found in a starter kit for example:
lock (SyncLock)
{
if (_cancelRequested == false)
{
_cancelRequested = true;
if (_uploads != null)
{
foreach (FileUpload upload in _uploads)
{
upload.UploadAsyncCancel();
}
}
}
}
That same thing can be accomplished through this:
lock (SyncLock)
{
if (_cancelRequested == false)
{
_cancelRequested = true;
if (_uploads != null)
foreach (FileUpload upload in _uploads)
upload.UploadAsyncCancel();
}
}
Isn't the second better to read? Plus this saves lines. For those of you who get paid by line, go ahead and put those in there, fine, but for those of you who don't, make your code more readable!