An old school bug

Posted in Software Development on August 25, 2011 by Christopher McPherson

I ran across a bug today that threw me for a few minutes. It reminded me it’s always good to get refreshers on the basics even when (maybe especially when) you’ve been doing it for years.

Here’s a boiled down version of the code that was misbehaving:

01: Filter=(reader,field,paymentDescription)=>
02: {
03: if (paymentDescription != "76")
04:        return null;
05:        ...
06: }

This code is from a tool that reads data from a data reader and outputs that data to a stream in a specific format for consumption by a third party. Most items are simply mapped from a field to a position in the stream but in some cases more complex formatting or parsing rules need to be applied. Lambda expressions provide a great solution for this scenario. We have a few generic field mapping classes that allow us to “plug in” specific formatting or parsing rules, while still reusing the base mapping classes. It works great and there are dozens of these that apply the formatting rules to the various record and field types.

BUT… this code returns null even when paymentDescription has the value of “76”! (What the?!) I’ve been doing this long enough not to immediately assume the compiler has somehow broken, but I have to admit it took me a minute or two get the idea of what was going on. Here’s a hint…if this code were written as a normal method it would look something like this:

01: public object Filter(IDataReader reader,
02:    string field, 
03:    object paymentDescription)
04: {
05: if (paymentDescription != "76")
06:        return null;
07:        ...
08: }

If you don’t see it already, the problem is that the comparison between paymentDescription and the literal string “76” is a comparison between an object and string, so it’s asking if the two are the same spot in memory rather than if their content is the same. The solution is to cast paymentDescription (which we know is a string in this case) to a string then the comparison works as intended.

The lambda syntax hid some of the details that I now realize I use as touchstones in my mental debugging checklist. If I’d seen that paymentDescription was an object and not a string, I’d have hit on the problem right away (that’s my story and I’m sticking to it).

This little bug, illustrates something that I’ve noticed a lot lately. When C# was first designed, one of the driving principles was readability and avoiding the syntaxes and mechanisms that had caused problems for C, C++ and other C-based languages. It seems that principle has taken a lower priority in favor of delivering more powerful and modern language features. That’s probably a good or at least necessary thing, but it means that more care has to be taken to deal with the more nuanced and cryptic syntaxes. And I need to update my debugging checklist.

Mocking and TDD

Posted in Uncategorized on April 22, 2010 by Christopher McPherson

I just started a new project with a repeat Firefly Logic client. I’m working with two very enthusiastic young developers on my team, and I get to introduce them to Moq and mocking as part of our unit testing strategy.  Both of these developers are new to mocking but they seem excited to jump in with both feet. I reached out to Moq initially a while back when I found the other mocking frameworks overwhelming. I’m looking forward to seeing how quickly my team picks it up. I’m hoping we can use the cool, geeky wow factor in Moq to help sneak in some best practice habits for TDD in general. It’s also a good leaping off point for a practical introduction to lambda expressions, which seguays nicely into linq.

Windows Phone 7 / Mix10

Posted in Uncategorized on March 15, 2010 by Christopher McPherson

Our company, Firefly Logic has been wrestling with adding mobile capability to our repertoire. In an ideal world, we’d be able to use familiar technology on a platform that people actually want to use. So far it’s been tough on both counts for .NET developers. The iPhone changed all the rules and over the last few years, nearly all of our clients requesting mobile software are specifically interested in the iPhone. The iPhone is a capable and compelling platform and people certainly want to use it.That’s why we’ve made the investment in learning to write applications for the platform. I think we’d call it a success, but a hard fought one. Objective-C, the language you use to write applications for the iPhone has a steep learning curve for .NET developers and the application frameworks are completely new unless you’ve done some Mac programming in the past.

All of this is why we’re so excited about Microsoft’s upcoming Windows Phone 7. As I type this, I’m sitting in the convention center at this year’s MIX conference in Las Vegas where Microsoft is planning to reveal the new platform to developers and designers. The first session is titled, “Changing Our Game”.

The rumor is that this platform is complete departure from the past and a serious contender in the mobile space. I hope so. It would be huge to have a serious  .NET option in the mobile space.

Visual Studio 2010 Multi Line Insertion Point

Posted in Software Development with tags , , , on March 11, 2010 by Christopher McPherson

I ran across a really cool little feature of Visual Studio 2010 the other day:

The ability to select a rectangular block in a VS text editor as been around for quite a while. If you alt+drag you can select by blocks rather than individual lines:

VS 2010 adds a neat little twist to this feature: multi line insertion points. So if I select this:

and type s-t-r-i-n-g, this is the result:

you can also alt-drag an empty box to create a multi-line insertion point:

Cool…

-McP

Hello World.

Posted in Software Development with tags , , , on May 24, 2009 by Christopher McPherson

Hello world. Welcome to my first blog post. 

My name is Chris McPherson. I’m a software engineer and one of the founding partners of Firefly Logic, a young software company in Nashville, TN. If you’re in business in Nashville, chances are you’re directly or indirectly involved in one of a handful of the big industries that thrive here. The most prominent from where I sit are healthcare, entertainment and publishing. In the healthcare arena Nashville has HCA Healthcare, one of the largest healthcare companies in the country, Vanderbilt Medical Center and the University, Meharry Medical College and countless others. On the entertainment side, we have the Country Music Association, CMT, The Grand Ole Opry, and Historic Music Row where it all happens. For publishing there’s Thomas Nelson, the leading publisher of bibles and there are several other large religious publishing houses headquartered here. 

When you’re a small independent software shop in a place like this, the opportunity to ply your trade in a wide variety of venues is enormous. And our happy band of intrepid byte crunchers has been lucky enough to be right in the thick of all this awesomeness over these last years.

I first met my co-founders while doing a extended tour of duty at HCA. We formed our company during that time and since then we’ve worked for the likes of CMA, the Grand Ole Opry, Cell Journalist, AO Smith, Shlumberger and many others. Along the way we’ve seen a lot, and learned a ton. I hope all this will translate to some occasionally interesting blog posts about technology and if that doesn’t work out, I can always talk about the places to score some killer Indian food or maybe a good cigar.

Right now, we’re in the middle of a large effort with Microsoft and CMA on a project for the upcoming CMA Music Fest, using Microsoft’s Silverlight and DeepZoom technologies. So, there’ll be a few posts about that I’m sure.

Anyway, thanks for dropping in and stay tuned, I might just say something interesting.

-Chris