I Don’t Like Arrays

The number one reason that I dislike arrays in .NET is the fact that they implement IList<T> explicitly, thereby burying useful members like IndexOf behind a cast or equally ugly calls to static methods on System.Array, and needlessly renaming the Count property to Length. As a result, it’s unduly difficult to change code that operates on an…

5

Exceptions, exceptions, exceptions….

I’ve made my first contributions to the FxCop team blog on a subject that’s near and dear to my heart and often controversial: the perils of catch (Exception). Take a look here and here. Update: The saga continues…

0

Opening the Coding Style Can of Worms

I find it troubling when different portions of code from the same project use different indentation and bracing styles. In my opinion, it’s much easier to read and maintain code that’s uniform in style. However, you won’t find me arguing that any one style is objectively better than any other. Although I have my own preferences,…

6

Presenting WeakDictionary[TKey, TValue]

This morning, I posted a base class to assist with implementing IDictionary<TKey,TValue>. As I mentioned this was just the first chunk of work required as part of my goal of building a generic dictionary which uses weak references for its keys and values.  While it’s reasonably easy to use WeakReference as the TValue in Dictionary<TKey,…

11

Implementing IDictionary[TKey, TValue] Isn’t Trivial

I recently needed a dictionary which uses weak references to store both its keys and values, but which otherwise tried its hardest to look and feel just like any other IDictionary<TKey, TValue>. Since there’s no such collection available in the BCL, I set out to build  it. I soon discovered that there’s a fair bit of plumbing required to…

3

Think Twice Before Throwing from Attribute Constructors

I had an interesting discussion recently about a subtle issue with custom attributes and I thought I’d share my conclusion. The question is whether it’s a good practice to throw ArgumentException from an attribute constructor as in the following example: [AttributeUsage(AttributeTargets.All)] public class MyAttribute : Attribute { private string value; public MyAttribute(string value) { if…

0

Mmm… Hungarian Notation…

I’m not a fan of Hungarian notation for variable names, particularly the variety where static type information is encrypted into impenetrable acronyms and repeated redundantly with every variable access. As the authors of The Pragmatic Programmer would say, it violates the DRY (Don’t Repeat Yourself) principle. If you change the variable’s type, then you need to make…

1

Hello? Is this thing on?

Allow me to introduce myself… I’m a developer on the Visual Studio Code Analysis team. I joined Microsoft in September of 2003 after completing my Computer Engineering degree at McGill University in my home town of Montreal and I’ve been working on FxCop and managed code analysis ever since. We’ve recently revived our team blog…

12