Developer

How I learned to stop worrying and love C#

After arguing for a long time that there's no difference between VB.NET and C#, Builder.com staff writer Lamont Adams is jumping on the C# bandwagon.


First off, my apologies to the fans of the Peter Sellers cult classic “Dr. Strangelove” for borrowing the film’s subtitle and adapting it as the headline for this article. I’ve got a confession to make, though, and that seemed the best way to get everyone’s attention. What I’ve got to say will be surprising to those of you who’ve followed my work here on Builder.com and previously on Developer Republic at our sister site, TechRepublic.com.

No, I’m not leaving Builder.com, so put those party favors away, please. My big confession is this: I’m forsaking Visual Basic .NET for C#. Yes, that’s right, after repeatedly professing my love for VB6, spending six years of my life working with it daily, and lecturing all of you that all .NET languages are created equal, I’m officially jumping off the VB.NET bandwagon. It’s been a nice trip, but I’ll be going with C# from now on. Why? Well, I’ve got my reasons, most of which have to do with syntax.

VB.NET is just too wordy
First off, I’m finding that, compared to C#, VB.NET is a child with a runaway mouth. It can’t stop talking, and has gotten awfully wordy. Consider that implementing an interface on a child class in VB.NET looks something like this:
 
Public Class AClass : Inherits SuperClass : Implements SomeInterface
 

In C#, the following simple code does the trick:
 
public class AClass : SuperClass, SomeInterface

You could argue that the VB.NET code is clearer, and I’d admit you’d be right. But I find I don’t need that clarity, especially when it comes to overridden or implemented methods. VB.NET crazily requires you to mark both of these with a keyword. C#, on the other hand, trusts you to figure out that a method with the same name as one on a superclass is probably going to be an override.

It doesn’t stop there. Operator overloading and inline variable declarations in things like for loops are a lazy programmer’s dream. I don’t think you can really appreciate ++ operators until you suddenly find you can’t use it anymore.

C# keeps me closer to Java
Another big reason why I’m liking C# more and more is that its syntax is more in line with that of Java and C++. Visual Basic, on the other hand, has evolved from its BASIC roots into its own peculiar dialect, the knowledge of which I’m increasingly unable to apply towards learning another new language.

As I learn more and more about building applications with C#, I find I’m learning more about Java and, to a lesser extent, C++, but not in the way I expected. I seem to discover more about Java from its dissimilarities to C# than the commonalities between the two languages and platforms. For example, take delegates, syntactic sugar offered by C# but not by Java. Turns out that Java provides essentially the same behavior via reflection. So, while looking for a Java equivalent to a C# construct, I inadvertently learned a lot about Java’s reflection API.

Now, .NET also has its own reflection implementation, which, surprisingly enough (note the dripping sarcasm) bears a remarkable similarity to that used by Java. This is just one example of the roundabout way in which knowledge of one language has led me to a discovery in another.

Fewer compromises for compatibility’s sake
My biggest reason for making the switch to C# might sound silly at first, but I find myself tempted by On Error Goto. Sure, .NET’s exception handling system is incredibly more advanced than Visual Basic’s old, archaic system, and I welcomed the coming of the exception to VB with open arms.

Then I found out that On Error Goto is still there, waiting to push me back into all the old bad habits I had when I was using VB6. Usually, I developed those habits because I had no other way to accomplish something. Other times, though, I was simply looking for novel (or should I say, lazy) ways to solve problems. Like the time I wrote an infinite loop to read some data from a file that depended on receiving a read past End Of File error to break out of the loop. Turning me loose in VB.NET is like letting a recovering alcoholic into a bar, as long as On Error Goto is calling my name.

Where do you come down?
Which .NET language do you prefer, and why? Have you changed your mind recently? Post to our discussion and tell us about it. Remember, it’s all in good fun.

Of course, the choice is yours
There’s one tune I’m not going to be changing soon; if there’s one nice thing about .NET, it’s that your language choice doesn’t really matter from a functional point of view. So, the choice truly comes down to the syntax that makes you most comfortable.

 

Editor's Picks

Free Newsletters, In your Inbox