Sometimes I look at a piece of code and find it hard not to sigh, especially when the developer has done something the hard way.

Take this piece of code, for example:

var key = EntityKeyFactory.CreateKey<ITsClassKey>(
    new object[]
    {
        aItemRequest.ItemName,
        aItemRequest.SystemName
    });

For reference, here’s the declaration of the CreateKey function:

public static T CreateKey<T>(params object[] aKeyValues)

Do you see the problem?

The developer’s working too hard - writing by hand code that the compiler should generate instead.

The key is the params keyword - instead of taking a couple of minutes to find out what the keyword meant, this developer ignored it and wrote code the long way over and over and over again.

Just for the record, here’s what the code should look like:

var key 
    = EntityKeyFactory.CreateKey<ITsClassKey>(
        aItemRequest.ItemName, aItemRequest.SystemName);

My rule of thumb: Don’t assume that because I don’t understand something, it’s irrelevant to me.

Comments

blog comments powered by Disqus
Next Post
Improving on POCO Associations  21 Jan 2010
Prior Post
CI, Builds and NAnt  15 Jan 2010
Related Posts
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle, solved  02 Jul 2022
A bash puzzle  25 Jun 2022
Improve your troubleshooting by aggregating errors  11 Jun 2022
Improve your troubleshooting by wrapping errors  28 May 2022
Keep your promises  14 May 2022
When are you done?  18 Apr 2022
Fixing GitHub Authentication  28 Nov 2021
Archives
January 2010
2010