Schoolboy Error Of The Day
This dumb mistake just cost me an hour spelunking around in the debugger:
var status = source.Substring(source.LastIndexOf("/" + 1));
(where source is e.g. “http://foo.com/status/all-is-good”)
Fortunately the ramifications were picked up in the acceptance tests, but the root cause wasn’t at all obvious from such a high level.
Lesson for the day – code is never too trivial to warrant unit testing.









Ha ha, I see what you did there, Ian! I must admit that I always struggle with getting substring operations correct off the top of my head – pesky off by one errors!
And blimey, C# really is like Java, but with different capitalisation, isn’t it? Is the status variable in your snippet a string, or is it like the old VB Variant?
It’s a String. The Substring method returns String, so the compiler can implicitly determine the type. This was a C#3.0 innovation:
http://msdn.microsoft.com/en-us/library/bb383973.aspx
Cheers. I wish Java had that. Instead of the redundant: Foo foo = new Foo();
I finally see it – spent a few minutes trying to see what was wrong, did the typical thing and went way overboard before noticing a simple mistake