Fog Creek Software
Discussion Board




C# vs VB.Net

Hello

Does anyone have any links to articles that discuss the merits of C# over VB.net or vice versa? (Or managed C++ for that matter.)

We have to make a decision at work as to which to use - a melange of two or three isn't going to be acceptable.

I myself have no real experience of either of them. My background is C++ with a slapdash of classical VB and VBA for knocking up test programs, automating spreadsheets etc. From the little I do know, C# sounds the better of the two, but that's more of a hunch than anything else. I couldn't make any kind of strong argument.

I'm open to VB: against C# is the fact that's it's a new language (and I feel we have enough new languages out there as it is), combined with the fact that going forward, we will have to continue to support Office-based solutions built around C++ COM addins/VBA automation. Given that we'll always have to know VBA and C++; why add C# into the equation? Surely it's the object models around .net that really matter?

I'm particularly interested in unbiased articles that discuss

Technical merits of the language
Productivity/Ease of use
Maintainability - does one language really lend itself to better coding practices over the other? can one language really help you to write "better" code?)
Projected market availability of programmers with expertise in the respective languages (now and in three years' time)

Any help you can give with this would be greatly appreciated.

Regards

Bruce Heldon

Bruce Heldon
Monday, August 12, 2002

I think the big difference is C# works better with old code, I'm no VB head, but I think that there isn't much support for interop built in there (or any?). Other than that they are pretty similar.

Others will have more valuable and accurate input though.

Robin Debreuil
Monday, August 12, 2002

Don't have any specific links to offer, I'm afraid, and I'd love to see such links too!

I've experimented with both VB.net and C#. Both have things I like and dislike, but at the end of the day there's not a lot to choose between them in terms of capabilities, and it really comes down to preference of style and syntax. They're designed to use the same compiler, so their capabilities should be identical (although C# does offer an unsafe mode for doing unpleasent low-level stuff).

I would say if you came from a VB background you'll be more comfortable with VB.net, and if your background is in C/C++/Java you'll be more comfortable with C#. However, if you don't want to deal with new languages, count both out since VB.net is quite a lot different from VB6.

You also have the option of C++. However, unless you really need to do messy pointer math and get at the hardware, I'd recommend keeping away from it. It may run a tiny bit faster, but in business applications you spend most of your time waiting for database calls anyway.

There are other oprions though. J# could be worth looking at. It uses the Java language (as far as I can see, unchanged from Sun's specification), on top of the .net framework. It should let you do anything you could do in VB or C#, but don't expect your apps to port to other Java platforms unless you also have a port of the .net framework.

I believe it's even possible to use Cobol, but you'd have to have a very sick mind (or a lot of legacy code).

James

James Shields
Monday, August 12, 2002

http://discuss.develop.com/

Matthew Wills
Monday, August 12, 2002

In terms of semantics, C# and VB.NET are identical.

I'm not kidding. They're both pretty thin layers on top of the CLR (Common Language Runtime). They have the same object lifetime, create objects at the same time in the same places, ... they even use the exact same runtime libraries (the .NET Base Class Library).

In terms of syntax, C# is very close to Java, & fairly close to C++. VB.NET is similar, but NOT the same as VB 6. The syntax has changed quite a bit.

I personally find the VB.NET syntax to be overly verbose, with lots of typing to say the same thing you can in C# in only a few characters. But that's taste. I know several VB 6 programmers who are switching to C#; I know several others who winced at the idea of case sensitivity for identifiers and ran to VB.NET.

C# also has the really nice delegate and event syntax that VB.NET lacks as far as I know.

As far as what you can do in one language and not the other:

C# lets you use unsafe code blocks, so you can directly muck with memory and use pointers if you want to.

VB.NET lets you do dynamic binding to object methods - the old "Dim o as Object" from VB6.

That's it for the list of technical differences.

Managed C++ is rather a different question, but trust me, you do *not* want to go there. :-)

I think you'll find that you will need to know at least some C# if you're programming for .NET. The main reason is simply this: most of the docs and books from third parties will be written with C# examples. So you'll need to be able to at least read the examples and translate them to VB.

Hope this helped,

-Chris

Chris Tavares
Monday, August 12, 2002

Would like to thank all those who replied. My own research yielded the following articles:

http://www.fawcette.com/vsm/2001_12/online/online_eprods/vsnet/default_pf.asp

http://www.chappellassoc.com/articles/article_informIT_QA_C.html

http://www.advisor.com/Articles.nsf/aid/SHERP42

I also paid for an article on Amazon by Daniel Appleman entitled "Visual Basic.NET or C#... Which To Choose?"

The conclusion of all these articles is pretty much the same: "there's no serious advantage to either language. It's purely down to which syntax you're happiest using". This is especially true if you're writing CLR compliant code. If you want to see *why* this is so, Daniel's article provides a pretty good analysis.

Thanks again

Bruce

Bruce Heldon
Tuesday, August 13, 2002

One area to look at is overall speed. The theory when the CLR was firs announced was that all .NET languages would run at the same speed because they're all calling the same routines in the CLR and they all compile to the MSIL rather than native machine code.

But some articles I've read take the same routine in VB.NET and C# and compile it to the MSIL. The C# compiler generates fewer lines of MSIL than the VB compiler. The cynic in me would suggest that MS has hobbled VB.NET to promote their new C#.

But my guess is that the real reason is that the slightly higher level VB.NET syntax simply compiles less efficiently.

YMMV.

Bob

Bob Crosley
Wednesday, August 14, 2002

It could also be that the C# and VB.Net compilers had different people working on them, and the C# people are better.

In fact, I'd bet on it - Anders Hjelsberg (sp?) is a true compiler guru.

Chris Tavares
Wednesday, August 14, 2002

I don't do much VB, so probably there are easy workarounds, but when hitting cls compliance I find the lack of uints etc a real pain when dealing with binary data and bit manipulation (eg, tag parsing). Might be there is something else that makes that easy in vb though, but from what I know it doesn't have the concept of unsigned integrals. Just a thought..

Robin Debreuil
Wednesday, August 14, 2002

I would love to see some statistics about the usage of each. Does c# have 50% of the ASP.NET marketshare or more?

Jacques
Thursday, April 15, 2004

I have read that some parts of C# are not CLR compliant.  Most people thought that C# was the flag ship of .net. Initialy nearly all .net books comming out were written in C#. However the language of preference for developers is now 60:40 in vb.net's favour. And I think higher for vb.net in government still.

Also visual studio seems to work better with vb.net allowing you to write code almost 20% faster.  The checking of camel case and all that stuff only happens in vb.net.

Josef
Tuesday, April 27, 2004

*  Recent Topics

*  Fog Creek Home