April 11th, 2007

run the fuck away

VB vs. C#

Wow. Okay, so I come from the C/C++/Java school of languages. Visual Basic has always felt amateurish to me, especially old-school VB. The more modern version, VB.NET, has lots lots of that feeling- it's a truly Object Oriented language now, but it still uses big clunky keywords.

For example, VB.NET code might look something like this:
Public Class Circle
  Inherits Shape

  Private _Radius as Double;

  Public Property Radius() as Double
    Get
      Return _Radius;
    End Get
    Set (value as Double)
      _Radius = value;
    End Set
  End Property
End Class


Big, spelled out keywords. The original language was designed to be easy for non-programmers, so lots of spelled out words. The same thing, in C#, is generally more preferable to a programmer:
public class Circle : Shape
{
  private double _radius;

  public double Radius {
    get { return _radius; }
    set { _radius = value; }
  }
}


Way more concise, very trim. Thats the sort of thing programmers generally prefer. It's not hard to learn a syntax, regardless of how cryptic it is (inconsistency makes it very hard, however). Since I do most of my work in VB.NET, since that's what people want their classes in, that's what I know the best. C# has always been something I've been meaning to pick up more about, but never have. Until today.

Today, I discovered that VB.NET has things C# lacks. In fact, despite the chunkiness of the keywords (which are usually auto-completed for you anyway), there are several very prominent things VB.NET has that C# lacks.

The first is the ability to have multiple indexed properties. Maybe there is a trick to doing this in C#, but I can't find it. If I want to have a property that represents a list, I've gotta implement a property against "this". For the non-programmers, suffice to say, it's kinda annoying. To be fair, I'm spoiled- most languages don't have the same simple property syntax that C# and VB.NET share, but it's annoying to have to do things the "old fashioned way" in order to make them work.

Secondly, in VB.NET, interfaces are not tied to method names. For the non-programmers- an "interface" is a contract. I promise to expose methods to meet the contract. In VB.NET, the stuff my class has doesn't need to have the same method names as the contract requires- it can map between them. This is great, because I can add interfaces to a class without having to worry about naming conflicts. C# does it the Java way, where names matter.

Thirdly, setting up event handlers, while somewhat more concise in C# is cryptic. Why the hell do I use the "+=" operator for adding those?