Home

VB vs. C#

June 12, 2012

The two big languages in .NET desktop development are VB.NET and C#. Both derive from long-lived and popular language families, and both have had their share of mutual dislike. Not dissimilar to the Capulets and the Montagues. C# has a proud history of hard-core development. It wasn’t that long ago that practically all serious desktop applications for Windows were written in C or C++. Visual Basic on the other hand has always been the softer language, aimed at non-professional programmers.

In the .NET framework the two languages have converged to an uncanny degree. The only real difference between them now is the ability to write unsafe code in C#, which you really oughtn’t be doing in the first place. But functionality isn’t everything. VB and C# were (are?) developed by different teams and they’ve come up with different approaches to similar problems. These differences have become fodder in the up-close war between Basic and C proponents, who now find themselves in uncomfortable proximity to the opposition.

Microsoft itself seems to be pushing C# harder than VB, for whatever reasons. But as my old* boss Andy leBihan pointed out, new programmers will always gravitate more towards VB, simply because it’s called Visual Basic, rather than C Sharp.

I’m not going to argue a position here, I’m happy working with both languages and I try to distribute new projects evenly between them. I started out as a VB programmer (VBScript, then VB5, then VB6, ultimately VB.NET 2005 → 2010) but have been working with C++ and C# for about 6 years now. There are plenty of things I think VB does better and plenty of other things that C# does better. Some of these are intrinsic to the language, others are mere implementation details of the VisualStudio code editor. Here follows a non-exhaustive list:

Things VB does better than C#:

  1. Events. Pretty much everything about them. Declaration, adding and removing handlers, raising events. Events are a bloody fucking nightmare in C#.
  2. Keywords. I like the self-documenting nature of VB language keywords. It makes them longer, but oh so much more readable. NotInheritable vs. sealed. MustOverride vs. abstract. Inheritable vs. virtual.
  3. End constructs. Pretty much all language constructs in C# are delineated by curly brackets. By the time you get to the bottom of a file, it’s not uncommon to see 10 closing brackets in a row. Good luck trying to find which ones mean what. VB uses keywords like End If, Next, Loop, End Function, End Class, End Namespace.
  4. Case-Insensitivity. I see no benefit whatsoever in having casing matter. All it can accomplish is confusion and it makes the autocomplete less easy to use.
  5. The Like operator. It’s just nice to have wild-card string comparison be so easily accessible.
  6. Interface implementations. I prefer the explicit statements for implementing interfaces as well as the suffix marking methods as specific implementations. C# is very muddy in this respect.
  7. Select Case is much easier to use than the C# switch construct.

Things C# does better than VB:

  1. It leaves scientific notation in code intact. There’s few things more annoying than having your 1e-12 literals automatically replaced with 0.000000000001
  2. Square brackets for indexing. VB uses round brackets for both method calls and array/list accessing. Square brackets would have been so much more distinguishable.
  3. Separate accessors for getters and setters. It’s not possible to have a public getter and a protected setter in VB. Forcing you to complicate the code with protected methods that kinda sorta look like the getters.
  4. Reflection Attributes. The notation is much cleaner in C#.
  5. /* …  */ commenting. VB does not allow for comments inside lines of code or for multi-line comments.
  6. is and as keywords. Much easier to type and read than TypeOf and TryCast().

As mentioned, this is nowhere near a complete list, however these are my major gripes. Due to the absolute horrid nature of events in C#, I prefer VB while developing GUI intensive applications but for pure code libraries I think C# is the more efficient language, at least once you’ve mastered all the keyword incantations.

* ‘old’ as in ‘no more’, not as in ‘geriatric’

6 Responses to “VB vs. C#”


  1. Good article! I also use both languages for day-to-day development, depending on what project I’m working on. These days I gravitate towards using VB mainly for two of the reasons you mentioned: the end constructs, and the self documenting nature of the keywords.

  2. tielc Says:

    Great article, I came across this looking for information on how to make the IDE work as nicely for C# as it does for VB. That might be something worth mentioning. Every source I read, says I pretty much need ReSharper to get the automatic nature of “Pretty listing (reformatting) of code. Constantly needing to remember to add (); to the end of ever method straight up sucks.

  3. Nathan M. Says:

    Actually, you can have split accessors on Properties.

    Public Property x As Integer
    Get
    Return m_x
    End Get
    Protected Set (value As Integer)
    m_x = value
    End Set
    End Property

    I like this article, though. I’m one of the forelorn few who has kept up with the language and I see so many opportunities out there for C# … I do a lot of Win32 API programming in straight C, and C# has this way of mixing paradigms that I haven’t gotten used to. A whole new set of keywords and ways of doing things. Like the use of the out and ref keywords (ByRef is fine, thanks), and the nuances in how they’ve adapted the C paradigm to the managed code paradigm.

    I read an article the other day that says Microsoft, internally, treats C# with more respect and doesn’t do any programming in VB for the framework. It’s like they just don’t like VB .NET, they feel it’s tied to an unforgiving legacy. While this may be true in a lot of ways (I have been, for years, a less-than-neat programmer, but fortunately no-one has to gaze at some of my more salient atrocities), I don’t think it’s AS true, anymore; that is especially true if you take the time to keep up with changes in the language. My biggest challenge, now, is trying to find ways to use the Async keyword in code I’ve already written to make it more adaptable to multi-threading.

    • David Rutten Says:

      Ok that’s cool about the property accessors. As it turns out I’m about to start working on version 2.0 of my main application and we’re going to move all code over to C# (I suspect mostly because my colleagues are mostly C++ guys who dislike VB). The only thing I dread is bloody events….

  4. theGreenCabbage Says:

    What are the benefits to VB for creating GUI-intensive applications? I was given the impression while working on winforms that C# excels all other languages when it comes to creating Windows-based interfaces since it works so well with Visual Studio.

    I would say some items listed above, for example, point number 2, 3, and 4 from “Things VB does better than C#” are all on matters of personal opinion. Some developers would say having curly braces indicating start and end of a statement more explicit, while also arguing that VB is too “wordy”, and prefer the succinctness of C#.

    Good points through out your post, however.

    • David Rutten Says:

      It doesn’t matter with regards to UI. I’m only familiar with winforms, not WPF, but both C# and VB access the winforms namespace in the same ways, and they both get to use the form designer in Visual Studio. Again, events are easier to manage in VB, but that is not a huge problem in my experience.

      I don’t quite understand what ‘works so well with Visual Studio’ means or how C# works better with VS than VB would.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: