This blog has been moved to

Wednesday, May 16, 2007

VB.Net Vs. C# (part 1)

Jeff Atwood from Coding Horror wrote a blog post the other day about C# and some of the deficiencies in the IDE, specifically the lack of automatic background compilation (C# and the Compilation Tax). The comments were very interesting. I love the fact that there are so many people out there that are passionate about development, but sometimes I find it a bit strange what they choose to debate.

I develop in both VB.Net and C#. I spend most of my time in VB.Net because that is the language that the company I work for chose (prior to me getting hired) due to their experience working with Visual Basic (VB6 and VBA). Before I went to work for them, I worked at Microsoft (as a contractor) on a C# project. I also do all of my own personal development using C#.

For all intents and purposes the languages are the same. They are both based on the same libraries and can accomplish the same tasks (perhaps with a couple of minor, mostly esoteric, exceptions). They both compile to the same bits and can easily work with one another when needed. If asked which language I prefer, my answer would probably depend on my mood at the time :).

For the most part, I think VB.Net is a better language, especially when working with events. C# forces you to write far more code into order to create or use events than VB.Net and using the handles keyword in VB.Net really makes removing event handlers easy. I also appreciate the background compilation and case insensitivity of VB.Net (as long as the auto-correct feature is on). I also like optional parameters, as long as they are used judiciously, and the greater flexibility of the Select statement over the C# equivalent switch. Other things I like about VB.Net is that I only have to declare the root namespace in the project settings which means I only have to declare a namespace if I am adding to it.

Of course, C# has some nice features as well. My favorite is that the language is designed to be terse. It also is closer to the underlying MSIL than VB.Net which means that when you write code in C# you will have a better understanding of what is going on behind the scenes (I am always having to explain how events work to VB.Net developers, I think most of them think it's some sort of magic). C# also has anonymous methods and coming in .Net 3.5 are automatic properties.

It seems that if you are working on a LOB (line-of-business) application and want maximum productivity, you should stick with VB.Net. If you want to learn .Net then C# is definitely the language for you.

However, I doubt that the productivity gains from using VB.Net are truly significant when compared to the overall schedule of any software project. I spend far more time eliciting requirements, designing, meeting, testing, etc then I do actually writing code. So in the end, personal preference will probably prevail. Of course, the whole team should be in agreement over which language a particular project should use. Just because it's possible to mix multiple .Net programming languages for a software project doesn't mean that you should.

No comments: