Deborah's Developer MindScape






         Tips and Techniques for Web and .NET developers.

July 22, 2009

VB or C#?

Filed under: VB.NET @ 2:15 pm

I learned to program using structured programming techniques with RSTS/E BASIC on a PDP 11/45 and progressed to VAX BASIC on a VAX 11/70. This was before database products were common, so we created our own data structures using hash tables and linked lists. Then came Ingres, and we moved to a relational database system.

After a brief stint on the mainframe, I moved to Silicon Valley and started using C and then C++. This was so long ago, that there was no Microsoft C++ so we used Zortek C++. This was my first introduction to object-oriented programming and I really liked it.

In 1992, I left the corporate world and moved into consulting. One of my first consulting projects was with Alan Cooper, the “father of Visual Basic”. At that point I was introduced to VB 2. It was so similar to what I had done on the VAX, that everything seemed familiar. The only thing I could not figure out how to do was to instance the user-defined types (UDTs). Come to find out, you could not. No real object-oriented programming features were available until VB 4.0.

When .NET first came out, I moved to VB.NET. There was so much that was different, it was nice to at least have some syntax that was familiar.

After spending months and months with .NET, I finally got to the point where I could actually code without looking something up every two minutes.

At that point I thought it prudent to learn C#. That allowed me to more easily attend talks or view sample code that was in C#. With my C++ background, some syntax was still familiar, but much was not (like event handling!).

Over the past few years, I have been doing more C# code, almost exclusively these past few months. I have found some things that I much prefer doing in C#, while others I much prefer VB.

But my clients still ask the question, “Should we move our team to VB.NET or C#?” Here is my reply:

  • If you are coming from C or C++ or Java, it is much more natural to move to C#.
  • If you are coming from VB 6 (or prior) or from VBA, it is much more natural to move to VB.NET.
  • If you are doing lots of “cutting edge” coding, you may want to consider using C# because often examples for cutting-edge topics come out first in C#. (Though Microsoft is working hard to change this. Look at LINQ as an example, the VB and C# 101 examples came out about the same time.)
  • If you are doing lots of XML coding, you may want to consider using VB because it has amazing XML features that C# does not have.

I also recommend that everyone get at least a reading knowledge of both languages. Then if an example is in one or the other, or if you go to a presentation in one or the other, you get the basic idea of what is going on.

5 Comments

  1.   Tim Murphy — July 22, 2009 @ 7:25 pm    Reply

    Great post. Can you provide specifics for comment ” I have found some things that I much prefer doing in C#”.

    I’m a vb.net programmer (history in Access rather than VB) and besides more code/examples on the net being C# I struggle to find where/why C# is preferable. I had to write about 30 lines of C# the other day and found it a giant pain in the butt. All those curly braces and semi colons just seem totally ridiculous.

  2.   DeborahK — July 23, 2009 @ 12:32 pm    Reply

    Hi Tim –

    Thank you for coming by the blog.

    These are a few right off the top of my head…

    VB: Dim tb As TextBox = DirectCast(sender, TextBox)
    C#: TextBox tb = (TextBox)sender;

    VB: Dim sampleString As String
    C#: string sampleString;

    VB: AddHandler SampleUserControl1.ValueChanged, _
    AddressOf SampleUserControl1_ValueChanged

    C#: sampleUserControl1.ValueChanged +=
    sampleUserControl1_ValueChanged;

    VB:
    Private _FirstName As String
    Public Property FirstName() As String
    Get
    Return _FirstName
    End Get
    Set(ByVal value As String)
    _FirstName = value
    End Set
    End Property

    C#: public string LastName { get; set; }

    [VB will be getting automatically implemented properties in VS 2010]

  3.   Tim Murphy — July 23, 2009 @ 6:09 pm    Reply

    Thanks for the reply. Personally I see only the last 2 items as a benefit although as you said VS 2010 will remove the last benefit.

    No doubt often the VB version is more verbose but I find more often than not the verboseness (if there is such a word) is easier to read and more natural.

    As you said it comes down to choice and where your roots in development started. As I started with dBase I’m use to languages of the 4GL nature as opposed to C# being 3GL.

    I really appreciate reading a blog that has VB & C# code. Keep up the good work.

  4.   Irfan — August 8, 2009 @ 4:18 pm    Reply

    It’s a great post!! However, I just don’t understand the reason of having 2 different languages where the underlying technology (IL) of both is not VERY different. I would agree if it was pre-.NET era where Object-Oriented C++ was more powerful than Object-Based VB. The expectations from both of those languages were quite different. C++ was used for more complex tasks using powerful data structures (linklists, trees, graphs etc.) and on the other hand VB was opted for rapid application development. But, where are we now where almost all of the features are available in both C# and VB.NET with some exceptions. Is it very difficult to implement those exceptions where they are absent?? Is it really impossible to implement XML Literals in C# and Statement Lambda in VB.NET?? if not then I honestly see only one language in future (C# very likely :))

  5.   DeborahK — August 8, 2009 @ 8:04 pm    Reply

    Hi Irfan –

    Thank you for visiting my blog.

    To reply to your question, VB10 (VS 2010) will have statement lambdas.

RSS feed for comments on this post. TrackBack URI

Leave a comment

© 2020 Deborah's Developer MindScape   Provided by WPMU DEV -The WordPress Experts   Hosted by Microsoft MVPs