I just finished writing a long 'ol email to a friend who wants to do a project in VB.NET since his background is in legacy ASP. Although my points have been illustrated by many over and over, I thought I would post what I wrote in the hopes others can add to my list.
- I realize you feel it will be easier for you, but that is only marginally true. What takes time is learning the .NET Framework classes (which were all written in C#, BTW), not the language syntax. For example if you want to get a substring in a string, how would you do it? I doubt you already know that it is:
//C#
string blah = "chad is raicheck";
blah = blah.Substring(0, 15);
'VB
Dim blah as String = "chad is raicheck"
blah = blah.Substring(0,15)Either way, you won't know how to do it off the bat. Like I said, this is not a VB vs. C# thing. The code is almost identical.
- Since you don't know either, it is the same learning curve either way. Believe me, I have had to learn both, and there is MUCH more support from websites, magazines, samples, books, etc with the C# community. Plus I have done pretty much everything in C# and can help you greatly.
- The code isn't THAT different once you know the basics.
Private m_user As User 'VB
private User m_user; //C#
'VB
Public ReadOnly Property TotalPosted() As Integer
Get
Return m_totalPosted
End Get
End Property
//C#
public integer TotalPosted
{
get
{
return m_totalPosted;
}
}VB is also much more verbose…look how many more words in VB :(. And you can make C# even more compact:
//C#
public integer TotalPosted
{
get { return m_totalPosted; }
} - For the last 4 years I have been adding to my code library and it is ALL C#. That means that even though we are writing our stuff in VB, I will have to spend 3x my time re-writing my website stuff that have already been working and tested.
- I am not going to rewrite my code library of thousands of line of C# code. .NET allows us to reference C# dlls from VB, so you will still be accessing C# and most likely having to read C# from my code. In fact, our website solution will have about 3 – 5 projects in it. Our website would be in VB, but then there are common functions classes which is already done in C#, the Data Access Classes that is already in C#, other Microsoft's Data Access Library that everyone uses which Microsoft wrote in C#, Microsoft Enterprise Library's and Exception Handling all in C# (also written by Microsoft). So no matter what, if you are debugging, you WILL be tracing through C# code.
- Like I mentioned above, it will take me probably 3x longer to do my job, since I will have to write so much from scratch. That is the equivalent of paying me 3x my regular hourly wage to do C# :(.
- It actually will be pretty easy to learn either language since you get to read and see all my code working with my comments of what is happening. I hired a brand new intern who didn’t know C# and I HEAVILY commented things and he caught on really fast.
- All my templates that I spent several days writing spits out C# code. I would have to re-write that for VB. In the long run it will still save us time, but it is an added expense.
- I said this on the phone, but there are things you just can't yet do in VB that you can in C#. Examples are this:
//C# this return an object Scott. This way I can call it by Test.Scott and it returns a "Scott" object
Class Test
{
public Scott Scott
{
get
{
return m_scott;
}
}
}
'VB - cant do it, must rename the object so they arent the same name. Now Test.Scott returns an object "ScottObject"
Class Test
Public ReadOnly Property Scott as ScottObject
Get
Return m_scott
End Get
End Function
End Class - THE BIGGEST REASON: I use many tools to help with coding such as: GhostDoc to help with documentation, Jetbrains ReSharper for code support which add HUGE productivity gains. Many of these only work with C#. To not work with ReSharper is like me telling you to not write code with Intellisense. It is that crappy.
- There is no XML comments in VB. This is pretty crappy. There are ways to go around it, but none are super perfect.
- There are cool things like incrementing shorthand you cant do in VB:
//C#
int i = 0
i++; //adds 1 to i
'VB
Dim i as Integer = 0
i = i + 1
One response to “Learning C# over VB.NET”
You got it right, C# rules. I know them both, and perfer C# over VB.NET, much cleaner, and had a clean slate to start with. And you are right 95% of .NET resources are in C#, and I can’t live without XML Comments. Documenting your code right, is one of the best programming practices one can learn, and C# makes this alot less painfull.