Interested in Sitecore?

Apply for our Mentorship Program by emailing your resume to chris.williams@techguilds.com. Check out our ASP.NET QuickStart and C# QuckStart Libraries. Below is my latest articles.

Wednesday, April 18, 2007

Top 7 reasons C# is better than VB.NET

I know this is preaching to the converted but in case your boss or some other developers you know are still stuck on VB.NET. Here is a list of reasons why C# is better than VB.NET.


  1. In C# the line ends when I type the semicolon. Allowing you to write all your code on one line of the need is required
  2. Features for VB.NET such as MVC are written and available in C# first then VB.
  3. Most third party control libraries that supply source code are in C# so any bug fixes you need to make will require C# coding
  4. Comments in C# are just better. Its easier to read them when not using Visual Studio
  5. Microsoft codes a majority of their stuff in C#
  6. You can more easily access the API from C#. No need for Declare statements
  7. Most C# developers can code VB but less VB developers can code C#.

9 comments:

Ranzige Bunzing said...

i really like VBs, but that's probably not the same VB as in your blog...

ranzigebunzing.blogspot.com

chrisw_88 said...

Actually, I am one of the rare ones that actually work with both. There are some things about vb.net that I find repetitive. I have finally given in to the request by many to create a vb.net guild. I have just created it and will try and post tips and tricks there as well. Hopefully others will email me and give me some links and things I can post. I work a lot more with c# so I always have lots of those.

shawnshaddock said...

1. In C# the line ends when I type the semicolon.


In VB .NET the line ends when I press enter... whats your point?


2. Increments/Decrements


I assume your talking about price++ and price-- in C#, as opposed to the equivalent in VB .NET price += 1 and price -= 1. Both are shortcuts for price = price + 1. The C# method is shorter but this is a pretty weak argument.


3. Money


I'm not even sure what this mean. If your trying to make fun of the Money type from back in VB6 then you fail, this is no longer a primitive type in VB .NET.


4. XML Documentation Integration, without a third party tool.


I assume your referring to XML Comments which you can also do in VB .NET:
Create XML Documentation in Visual Basic


5. Error Catching


Try...Catch? This is also available in VB .NET:

Try

Catch ex As Exception

End Try


6. You get to act really snotty to VB.NET developers


If your topic was "Top 10 reasons it's better to be a C# developer" then this argument would make sense.


7. The source code to the C# compiler is available from Microsoft and Novell.


I was unable to check your link to the source code from Microsoft because the link is broken. As for Mono from Novell, this is completely open source, and yes it has support for VB .NET.


8. C# has Operator Overloading


So does VB .NET:

Public Shared Operator =(ByVal left As Class1, ByVal right As String) As Boolean

End Operator

Public Shared Operator <>(ByVal left As Class1, ByVal right As String) As Boolean
End Operator

Public Shared Operator =(ByVal left As Class1, ByVal right As Integer) As Boolean

End Operator

Public Shared Operator <>(ByVal left As Class1, ByVal right As Integer) As Boolean
Try

Catch ex As Exception

End Try
End Operator


9. Comments in C# are just better.


VB .NET
'Dim count = 1

C#
//var count = 1;

The VB .NET way is actually shorter. You must be referring to the ability to comment multiple lines of code in C#. The visual studio comment button does not even use this method when commenting multiple lines. It simply add's // to every line. I personally prefer this method.


10. Regions in C# are far better.


You would need to explain why they are better. I personally prefer working with regions in VB .NET because the environment will automatically put the #End Region for you. I think this one comes down to person preference.

shawnshaddock said...
This comment has been removed by the author.
chrisw_88 said...

- VB.NET ends when you press enter but some cms solutions that allow you to embedd html or code only allow single line statements
so writing if statements on one line followed by the : should allow you to continue your code like it did in the old standard basic language and in c#.
This is a limitation of vb over its predecessor and also c#

- This list was generated prior to 2008 so my point being that VB gets all the features after everyone else has them.

- If you did not include any components in your project that were written in c#, then your vb.net source code would be larger and thus more difficult to maintain than the c# equivalent.

eg. Virtually every class in vb needs Option Explicit. C# is smart enough always do it.

eg. Declare <API> needed for all api calls where as C# already has them for you.


- Error Catching - this was not introduced until 2005 so the point is it took longer for them to implement this feature in vb.

- Comments in C# are just better. The reason they are better is that at a glance its easier to see // over a ' in your code


Conclusion, as time goes on more c# features will be added to vb but then again c# will keep growing and always get more sooner.
Case in point, LINQ was released for C# first then VB got it.

It boils down to that these languages have two different purposes. VB is for rapid development. Get it up there fast. But when it comes to maintenance and getting the latest functionality from Microsoft, you need to use c# or possibly a hybrid of the two.

Think of it this way, would you write your database server in vb or would you simply use sql server. If the answer is you would use sql server then you agree with me. VB.NET is always going to need c# components the same as C# applications are always going to need 3rd party databases and components.

McCann said...

I agree with Chriss on this one. it the grand picture vb will always be the little sister

shawnshaddock said...

- VB.NET ends when you press enter but some cms solutions that allow you to embedd html or code only allow single line statements
so writing if statements on one line followed by the : should allow you to continue your code like it did in the old standard basic language and in c#.
This is a limitation of vb over its predecessor and also c#


Can you give me an example of what these "CMS Solutions" require?

- This list was generated prior to 2008 so my point being that VB gets all the features after everyone else has them.

It does not matter that this was posted prior to 2008, everything I wrote still applies. If your point is that VB .NET gets all the features after everyone else then you failed to make that point in your original post. Plus there are a handful of features that VB .NET has that are not available in C# such as XML literals and optional parameters. Optional parameters will be available in C# 4.0, so C# is getting this feature after VB .NET

- If you did not include any components in your project that were written in c#, then your vb.net source code would be larger and thus more difficult to maintain than the c# equivalent.

I'm not sure what you mean by this... can you elaborate?

eg. Virtually every class in vb needs Option Explicit. C# is smart enough always do it.

Option Explicit can be turned on by default in Visual Studio along with Option Strict, Option Compare, and Option Infer.

eg. Declare <API> needed for all api calls where as C# already has them for you.

Can you give me an example?

- Error Catching - this was not introduced until 2005 so the point is it took longer for them to implement this feature in vb.

Again, this was posted after 2005 and the original post never said anything about VB .NET taking longer to get this feature.

- Comments in C# are just better. The reason they are better is that at a glance its easier to see // over a ' in your code

The whole line turns light green by default... And this can be customized to any color you want. That's not enough? You could always use REM in VB .NET to comment out a line, thats even easier to spot then //

Conclusion, as time goes on more c# features will be added to vb but then again c# will keep growing and always get more sooner.
Case in point, LINQ was released for C# first then VB got it.


LINQ was released as part of .NET Framework 3.5 along side Visual Studio 2008. This included LINQ support in VB .NET.
Visual Basic .NET


It boils down to that these languages have two different purposes. VB is for rapid development. Get it up there fast. But when it comes to maintenance and getting the latest functionality from Microsoft, you need to use c# or possibly a hybrid of the two.

Where did you read that VB .NET's purpose is RAD? It would be very rare to find a problem that can be solved in C# but not in VB .NET. I also fail to see how C# surpasses VB .NET in regards to maintainability.

Think of it this way, would you write your database server in vb or would you simply use sql server. If the answer is you would use sql server then you agree with me. VB.NET is always going to need c# components the same as C# applications are always going to need 3rd party databases and components.

I don't see the comparison nor do I understand what you mean when you say VB .NET is always going to need C# components. The language that components are written in is irrelevant due to the fact that in the end they are all compiled to IL. When you obtain and consume a 3rd party component in your applications you will have no idea what language that component was written it nor will it matter.

To see a comparison of the two languages check out Comparison of C Sharp and Visual Basic .NET

chrisw_88 said...

- VB.NET ends when you press enter but some cms solutions that allow you to embedd html or code only allow single line statements
so writing if statements on one line followed by the : should allow you to continue your code like it did in the old standard basic language and in c#.
This is a limitation of vb over its predecessor and also c#

There are certain popular cms packages that allow you to place code segments in their widgets.
Unfortunately they often do not allow line breaks. The issue here is the if statement does not allow the endif on the same line

if x=1 then b=2 else c=3 endif : print b

This line would give an error because endif is not allowed you have to include everything after the else in the else clause.


- Virtually every class in vb needs Option Explicit. C# is smart enough always do it.

These options are turned on but still if you look at the physical code files they are extra lines of code in every file.

- Declare $lt;API> needed for all api calls where as C# already has them for you.

Given that you have to ask about declare api it just shows that you have never made native api calls and thus probably have not done
secure Vista applications. Although you may have used the clunky workaround of executing an external process.


- Comments in C# are just better. The reason they are better is that at a glance its easier to see // over a ' in your code

The whole line turns light green by default... And this can be customized to any color you want. That's not enough? You could always use REM in VB .NET to comment out a line, thats even easier to spot then //

Yes provided you have Visual Studio but sometimes designers and web producers do not have it. They have dream weaver and if your server is doing compile
on the fly you may even be using notepad to make minor changes.

Conclusion, as time goes on more c# features will be added to vb but then again c# will keep growing and always get more sooner.
Case in point, LINQ was released for C# first then VB got it.

LINQ may have been released with 3.5 but LINQ for entities was released later.

But anyways, here is another such example. It seems MPF only
exposes some of its api but the code in c# is supplied so you can extend your project with the addional features. you would have to use C# and wrap it in a component vb could use or write your app in c#:

http://social.technet.microsoft.com/Forums/de-DE/vsx/thread/c258e021-4753-4956-ac3b-0e79900ece6d

Take a look at mvc. Note that it is written in c# so if you need to do tweeks or fill in holes in the microsoft api you need to develop in c#.

http://forums.asp.net/t/1392176.aspx

When you buy third party components with source code, you generally get c# code to recompile not vb.net so you have to know and use it either way.


It boils down to that these languages have two different purposes. VB is for rapid development. Get it up there fast. But when it comes to maintenance and getting the latest functionality from Microsoft, you need to use c# or possibly a hybrid of the two.

As for reading it is rad, you sent an email to Stephen McCann point out that very thing as a reason vb is better than c#. It is for rapid application development and as we all know. If you are developing an application in a hurry you are more likely to make mistakes and find pieces that don't fit together just right.

Susan Fischer said...

Don't think of it as one language better than another think about what Microsoft uses for its products. Think about what power developers use for their apis.

Is Beta better than VHS? Is BlueRay better than HD DVD? No, but given that most people have a vhs vcr and an Blueray player you are more likely to get your movies in Blueray.

The same goes with C#. Yes you can program in vb.net but you have to still use the components developed in C# and if its broken rely on 3rd party support or buy the C# code and fix it yourself.