It’s time to take the gloves off.  I’ve tried to be fairly diplomatic and not stomp all over peoples toes in my previous blog postings.  I’m done, it’s not me, if you know me I’m not diplomatic or fair, I’ve got a mean streak and I just hate.  My undying hatred for stupid people and all other things stupid has multiplied over the last dozen or so consulting hours.

To give the story some context we inherited this bit of code from a [pathetically useless, completely incompetent, but pretty] shop that was eight months past their deadline, our customer is fed up with their performance and will go to almost any lengths to get some functionality added.  That’s where we come in.  This code started it’s miserable life a pathetic version of a 4 tier ASP.NET and VB.NET application.  4 tiers because that’s what the code generator thought every application should be, so you’ll inherit twice for no reason at all, every bit of 40 some odd classes are empty inheritance.

So, after a cursory look through their code we found two very light weight middle tiers and some horrendously heavy and duplicative presentation tier.  Our expertise is C#, sure we can read VB.NET and write it as bad as everyone else with a gun to our head.  So I was in the market for a VB.NET to C# converter.  [aside] I’m completely disinterested in you telling me that in the end VB.NET and C# and for that matter any other .NET Framework language are fundamentally the same and compile down to the same IL, so stop complaining about language and just do your job.  F#!* you.[/aside]

Before I completely flame on VBConversions VB.NET to C# converter let me say this.  The codebase we inherited couldn’t have been more poorly written if you tried, Option Explicit was not ON and there was no typing anywhere (except in places that completely didn’t make sense, and even then those types weren’t appropriate for the apparent intention of code — like using a long instead of a bool, etc). 

I have no idea how hard code conversion is, but for the $118 we spent on this product I think we got one regular expression that looked for the end of line and replaced it with a ;.  We might have gotten a few more to sprinkle around some { } instead of END whatever, but in general that’s it.  The product even had the audacity to claim it converted with 96% accuracy, or some such fallacy.

Ugh, bullshit.

Every indexer was wrong, they didn’t bother changing ViewState(foo) to ViewState[foo], or array, or Session, or DataReaders or anything else.  They didn’t bother giving us () where we would have liked to see them; places like object instantiation (Foo foo = new foo() ), ToString.Trim.ToUpper instead of ToString().Trim().ToUpper(), and other sorts of uselessness.  These fall into the inexcusable category, we’re talking about going to C#, lets pretend we know something about the language.

Then we get into some of the horrible things you can do with VB.NET so lets try to duplicate it in C#.  Things like:

txtLastAnnualWageDateYear.Text = System.Convert.ToString(DateAndTime.DatePart(DateInterval.Year, with_1.lastAnnualWageDate, 1, 1));

Cool, that little with_1, just a placeholder to deal with the With syntax in VB.NET.  So that’s ugly, DateAndTime, come on, lets just do:

txtLastAnnualWageDateYear.Text = with_1.lastAnnualWageDate.Year.ToString();

And this is only the beginning.  The VB.NET source used methods with optional parameters, one in particular was a method call with 6 parameters, 4 optional.  So the call to the method in C# was MethodName(param1, param2).  Of course that won’t compile because we need 6 parameters.  Dammit go find the Method signature and pull out the default values, oh wait, when we converted to C# we left the parameters but stripped out the “= whatever” so they weren’t optional any more.  WTF?

if (myRow["claimStatusCode"] == ConfigurationSettings.AppSettings["ClaimStatus_Saved"] & System.Convert.ToString(myRow["SourceName"]).ToUpper.Trim == ConfigurationSettings.AppSettings["Source_Efile"].ToUpper().Trim())

Yeah the brackets are right, global search and replace using regular expressions did that.  But notice something interesting?  The “&” instead of “&&”.  To our best guess in an attempt to mimic VB.NET’s non short-circuiting behavior (in the expectation that one of those clauses might actually cause a side effect in code and therefore all need to be evaluated) we get & and | for all IF conditions that don’t use OrElse and AndAlso.  Awesome.

Oh, and in my attempt to deal with another problem, hacky namespace declarations (mainly namespace Root { namespace Other.Qualified.Namespace ) I came up with a regular expression search and replace that killed VS.NET repeatedly, or so I thought, it just took several minutes on the first find, then I replaced the next few occurrences in place, and several more minutes to return on the next match.  Not wanting to wait i said “Replace all”, 5 hours later it had chewed through 4 or 5 files, awesome.  AWESOME!

It’s taken 12 hours but we’ve got the web app converted and compiling, we’ve got the data layer to deal with, somehow we have to put back together all the optional parameters that were just outright dropped and maybe we’ll be able to see if this thing works with an ugly albeit C# codebase.

Title courtesy Marilyn Manson who has other jewels but we’ll save them for another occasion.

Now playing: Das Ich - Der achte Tag