My dirty little secret

|

I have a secret confession... l'm loving VB.NET.

I have been using C# solidly ever since the very first beta of the .NET Framework back in 2002; my background is all VB right from VB3 to VB6 (version 6d to be precise) and every version in between until I met .NET. I did a little C++ here and there, even tried Java a couple of times, but when I saw C# I loved it (and still do) and it has paid my mortgage and fed my family ever since. Back in 2002 I did attempt to be multilingual and learn .NET in both VB and C#, but as the learning curve increased the more my skills in VB decreased. Until today...

I'm involved in writing some training material where I have to produced any code samples in both C# and VB. I was not looking forward to the prospect of writing VB code again; seeing it more as an overhead to the project than anything else, a chore even. However, I initially wrote some code to create a FixedDocument using C# and thought I'd have a quick stab at writing it in VB, just to see what it would feel like after all this time...

It felt natural, it felt like I had come home. The syntax just flowed out of my fingers, and I did not make any of the C# school boy errors of putting semicolons where they shouldn't be or using forward slashes for comments. I did have some funky C# syntax to deal with, that I had no idea how to convert - but then there was Lutz and Reflector on hand to help with the conversion (who knew how useful de-compilers would be before Lutz made it so easy?)

Here's the C# code that I wrote first (the third line was the one giving me the translation issue):

FixedDocument doc = new FixedDocument();
PageContent p1 = new PageContent();
((IAddChild)p1).AddChild(CreatePage("Hello, World!"));

Now for the VB version:

Dim doc As FixedDocument = New FixedDocument
Dim p1 As PageContent = New PageContent
DirectCast(p1, IAddChild).AddChild(CreatePage("Hello, World!"))

(/me slaps head, "Oh(!), DirectCast, I should have thought of that(!)") I would never have figured that out on my own, really, never!

In summary, I'm a C# head and probably will be for many years to come, but I have a lot of love for VB.NET (that does not make me a bad person); there may even be some abandonment issues that I need to address to make my peace with VB, but I think, finally, I can and today was that first all important step.

No comments: