Entries categorized 'Blog' ↓

Empty Catch Blocks

I’ve just found 22 examples of this anti-pattern in a small .NET project:

emptycatchblock

Oh yes, the empty catch block. Joy of joys.

Declaring an empty catch block is equivalent to professing that:

"Sometimes this code I’ve written fails. I don’t know why. I don’t really care. Please don’t tell me when it happens. I can’t hear you. La la la…"

*sigh*

If I ruled the world, empty catch blocks would be invalid in C#. Is there ever any reason for using them?

SQL 2008 - Missing Indexes Hints

Improvements to the Execution Plan UI in SQL Server Management Studio 2008 sure do make it a doddle to improve query execution time.

A client just reported that a particular stored procedure kept timing out.

Viewing the Estimated Execution Plan for this query displayed a nice green message advising of a potentially missing index which could improve performance by >95%:

amc1

Right-clicking and selecting “Missing Index Details” then brings up a new query window containing the index creation DDL (I had changed the index name by the time I grabbed this capture):

amc2

Dead easy. Repeating the process identified a second index which could further improve performance by >80%.

Of course, you still need to bear in mind other queries which access the table, and the effects on inserts/updates of creating additional indexes, but even so, this really helps the workflow.

The suggested indexes functionality was actually available in SSMS 2005 too, but the results were buried away in the XML version of the execution plan, and obscure properties windows, rather than being so in your face.

SRP Doesn’t Stand For “Several Responsibility Principle”

I know it should no longer come as any surprise to me, but I just found this method (and several others like it) lurking in a Data Access Object. Grrr…

/// <summary>
/// Send an email to notify that accrual data has been successfully uploaded
/// </summary>
/// <param name="accrualUpload"></param>
/// <param name="recipientAddresses"></param>
public void SendSuccessfulUploadEmail(AccrualUpload accrualUpload, Collection<MailAddress> recipientAddresses)

Much of software design / architecture isn't technically difficult, it just requires a little thought - "where does this functionality belong?"; - rather than forcing code into the first class you come across.

Square Peg in a Round Hole

Did I mention how useful NDepend is in exposing idiocy like this? I think I did. And I really should get round to blogging about how handy CodeRush and Refactor Pro are for cleaning up such smells.

.NET - Retrieving the Month Name

Here’s another amusing method I recently found in some production code which comes straight from the “can’t be bothered to learn the framework (or how to Google)” style of programming:

/// <summary>
/// Converts a month number into the name
/// </summary>
/// <param name="monthNumber"></param>
private string GetMonthName(int monthNumber)
{
    return String.Format("{0:MMMM}", new DateTime(1969, monthNumber, 1)); 
}

I wonder what the significance of 1969 is? Year of the author's birth, perhaps?!

Aside from being hacky, there is a performance implication to unnecessarily creating new DateTime objects and performing string formatting in this way. In my tests, I’ve found that this method is around 18 times slower than simply calling System.Globalization.DateTimeFormatInfo.CurrentInfo.GetMonthName(monthNumber).

Ian Nullson

Oh dear. Royal Mail have been taking tips from Creative:

RoyalMail

Agile Yorkshire @ The Pub – Gojko Adzic, 10th June

If you’re in the Leeds area next Wednesday, why not come along to this Agile Yorkshire session?

10th June - Gojko Adzic: Slim, The Future Of FitNesse

Details

This talk will introduce Slim, the most important upgrade to FitNesse in years. Slim is the new test runner which promises to bring platform interoperability, easier integration, a much simpler programming model and lots of small helpers that will allow us to write and maintain executable specifications and acceptance tests easier. This is a session for .NET and Java developers. Some prior exposure to FitNesse and FIT would be beneficial, but not required.

Speaker

Gojko Adzic is a software craftsman with a passion for new technologies, programming and writing. He runs Neuri Ltd, a UK-based consultancy that helps companies build better software by introducing agile practices and tools and improving communication between software teams, stakeholders and clients. See http://gojko.net/about/ for more details.

Venue: Victoria Hotel, Central Leeds

Date/Time: Wednesday, 10th June, 6:30pm sharp.

More details: http://www.agileyorkshire.org/

Referral Questions

I love looking through the Traffic Sources section of my Google Analytics reports to discover how people found my site.

To the end of 2008, over 75% of visits had come via search engines. There are thousands of weird keywords and phrases by which people have somehow managed to stumble across my little home on the web, but the ones that entertain me most are when people type entire questions into a search engine.

I thought it would be a nice idea to share some of these questions posed by previous visitors to ianfnelson.com, and perhaps attempt to provide answers where possible. I’m helpful like that. Here goes:

 

Can You Tell Me The Dates and Names Of The Monarchs From 1066?

No. But Wikipedia can.

Can You Get Married At York Minster?

I believe it’s possible, if you have some kind of special relationship with the place.

Does Ian Nelson Have Cars?

He does.

Do I Have To Tell My Boss That I Have NF?

As in the flesh-eating virus?! It might be a nice idea.

Does Grecian 2000 Actually Work?

How should I know? Cheeky bugger.

Does My Japanese Wife Need to Take The “Life In The UK” Test?

If she wants to settle in the UK, yes.

How Are They Consumed?

They’re gulped down quickly.

How Much Do Avanade Pay?

Not enough.

How Much Is A Pint In Riga?

Last time I was there, about £1 (€1.11, $1.51).

How Much Is A Shag In Riga?

Er, I didn’t find out.

How Old Is Ian Nelson?

33.

How To Annoy A Four Year Old?

Insist that they’re only three?

How To Avoid Jury Service?

Serve a prison sentence, or develop a mental health problem.

How To Get Married In Newcastle Upon Tyne?

Carefully.

How To Improve Performance In NHibernate?

Buy and use NHProf.

How To Peel a Banana?

I do it this way.

How To Peel a Banana Strangely?

Er, with your feet?

How To Seem Genuinely Appreciative At A Bridal Shower?

Ha ha! How about considering how lucky you are that friends and/or family care about you enough to throw such an event, and shower you and your child with gifts?

Is Ian Nelson Gay?

No.

Is Ian Nelson Married?

Yes.

Is Ian Nelson Weird?

Slightly.

Was This Information Helpful?

Not so much.

What Day Of The Week Was 25 September 1998?

Friday. I had quite a thirst going that day.

What Do Schoolteachers and Sumo Wrestlers Have In Common?

Find out by reading Freakonomics.

What Does “Ey Oop” Mean?

“Hello”.

What Is “Heather” In Gaelic?

“Fraoch”.

What Is Jury Service Like?

See my blog post on the experience.

What Is Santa Claus Postcode?

In the UK, SAN TA1. In Canada, HOH OHO.

What Is The Easiest Munro To Climb?

Probably Carn Aosda. Dull as dishwater, though.

What Is The Role Of Ian Nelson?

I wish I knew.

What Nation Gave The World The Beatles?

They hailed from Liverpool, England.

What Time Do You Make It?

Five past Three.

Where Did Telnet Go?

It’s not installed by default in Vista. Here’s how to add it.

Who Sang “We Close Our Eyes”?

Go West.

Who Sings “Bruised But Not Broken”?

Joss Stone.

 

This was a public service from ianfnelson.com :-)

Ian Nelson, MCPD

Well, for the record, I passed MS exam 70-553 yesterday on my second attempt, which makes me a Microsoft Certified Professional Developer – Enterprise Application Developer:

Microsoft Certified Professional Developer

And I also acquired a few new MCTS certifications as a happy by-product:

Microsoft Certfiied Technology Specialist

My full transcript, including “legacy” certifications, is here.

Phew! I think that the time has now come for me to take a bit of a break from the certification circus. They are a nice-to-have, but the opportunity cost is too high – there are many other ways in which I can spend what little spare time I have to better develop my skills.

New Office Photos

I promised you some photos of my new office a while back, didn’t I?

OK, here you go. Click for larger versions.

The Desk

The Desk

‘Puter

'Puter

One Of These Books Is Not Like The Others

One Of These Books Is Not Like The Others

Bits n Bobs

Bits n Bobs

In Gnasher We Trust

In Gnasher We Trust

Typemock Bundle Launches

The folks at Typemock have come up with a cunning viral way to market a new software bundle comprising of their renowned Typemock Isolator and Ivonna tools. Having mentioned Typemock in this blog previously, and being something of a unit testing zealot, I’m happy to be a pawn in their campaign!

Unit Testing ASP.NET? ASP.NET unit testing has never been this easy.

Typemock is launching a new product for ASP.NET developers – the ASP.NET Bundle - and for the launch will be giving out FREE licenses to bloggers and their readers.

The ASP.NET Bundle is the ultimate ASP.NET unit testing solution, and offers both Typemock Isolator, a unit test tool and Ivonna, the Isolator add-on for ASP.NET unit testing, for a bargain price.

Typemock Isolator is a leading .NET unit testing tool (C# and VB.NET) for many ‘hard to test’ technologies such as SharePoint, ASP.NET, MVC, WCF, WPF, Silverlight and more. Note that for unit testing Silverlight there is an open source Isolator add-on called SilverUnit.

The first 60 bloggers who will blog this text in their blog and tell us about it, will get a Free Isolator ASP.NET Bundle license (Typemock Isolator + Ivonna). If you post this in an ASP.NET dedicated blog, you'll get a license automatically (even if more than 60 submit) during the first week of this announcement.

Also 8 bloggers will get an additional 2 licenses (each) to give away to their readers / friends.

Go ahead, click the following link for more information on how to get your free license.