Why I prefer c# over VB

A couple of weeks back I was asked by a friend of a friend why I code in c# over VB. I didn’t give him a very good answer at the time as I just couldn’t pinpoint the reason. Since then I have had a real good think about it and have come to this conclusion. It just looks bulky. Not a good reason I know. I am not what you would consider a power developer, I use .net for relatively simple tasks and there isn’t any feature I would consider using one language over the other. So for me it just comes down to aesthetics. I can and have programmed in both classic VB and VB.Net and it was only about 4 years ago that I decided to have a look at c#. Now when I look at old code I have written in VB.Net I not only shudder at the overall crapness of my code, but also the amount of non-whitespace. A simple while loop in VB looks less clean than its cousin in c#.

   1: Dim counter As Integer = 0
   2: While counter < 20
   3:     counter += 1
   4: End While
   1: int counter = 0;
   2: while (counter < 20) 
   3:       {
   4:          counter++;
   5:       }

For me the second code example is easier to read, I know the while construct has ended by the placement of the closing brace I don’t need 8 superfluous characters to tell me that.

I was brought up with BASIC on the Commodore 64 and then Amiga BASIC through vb2,3,4,5 (didn’t really use vb6), then VB.Net and now c#. I do feel to a certain extent a bit of a traitor.

As has been reported elsewhere, word is that inside Microsoft they are trying to align the language development teams more so a particular feature that becomes available for one language will immediately be available in others. Will this blur the choice between languages?

10 Comments

  • Does the operator "+=" really exist in VB? Shouldn't it be 'counter = counter + 1'?

  • One way or the other, I would use 'for' loop in both cases (languages)...

  • Agreed, man. Years ago I had to move from C++ and Java to VB and (oh god) Lotusscript. What a nightmare!

    Remember While/Wend? WTF was that?! :)

  • That's probably not the best example to get your point across as in VB.NET you would normally use:

    For i As Integer = 1 To 20

    Next

  • @CW2 - Yes += is perectly valid in VB.Net

    @Mark - I agree in what you are saying, but for this I wanted a like for like example.

    @joelvarty - Wend...oh the memories!!!

  • I too was brought up on C64 basic, GWBasic, VB3-6 and ASP. So glad i switched to C#.

    C# is cleaner and easier to read. VB is a little like reading itailian, very long and slow to read. Noisy to read.

    Here is a nice short example

    for (int counter = 0; counter &lt; 20; counter++)

    &nbsp; &nbsp;if (counter.Equals(5))

    &nbsp; &nbsp; &nbsp; &nbsp;Console.WriteLine("# 5 is alive.");

  • VB *still* doesnt have a "using" construct like c#.

    For those that are unaware of "using":

    using(SqlConnection conn=GetSqlConnection())
    {
    conn.Open();
    //do something in db
    } //using statement guarantees dispose is called.

    As opposed to VB:
    Dim conn as SqlConnection = GetSqlConnection()
    Try
    conn.Open()
    'do something in db
    Finally
    conn.Dispose()
    End Try

    again, a lot more verbose.

  • This is valid in atleast vb.net (target 3.0, VS 2008)

    Using conn As SqlConnection = GetSqlConnection()

    Conn.Open()
    End Using

  • I think you have quite a good reason for choosing c# over vb. I come across some people who say they don't ever use vb because it's too "easy".
    Whenever you hear this statement, you can guarantee that their programming capabilities extend to 'Hello World' applications, because they've proven they don't know much about programming.

    The reason people would prefer different languages would be because they have better support for either hardware or software. For instance vb wouldn't be good for hardware programming. But it's excellent for databasing.

    Like you, i go for a language that's easier for me to read. Except my choice would be vb. c# does look shorter and to the point, but for me, it's easier to remember words rather than symbols.

    As a bonus, since you do a lot with c#, you'll find it easier to program in most languages, than those using vb :)

  • microsoft gives more attention to C#.

Comments have been disabled for this content.