Monday, March 8

Why choose C# over Visual Basic (VB)?

http://en.csharp-online.net/CSharp_FAQ:_Why_choose_CSharp_over_Visual_Basic_%28VB%29

The choice between C# and Visual Basic .NET is a subjective one based on prior experience. C++, Java, and J++ programmers will prefer the non-nonsense, terse syntax of C#. Visual Basic (VB) programmers may prefer to stick with the devil they know—Visual Basic .NET's case-insensitive, pseudo-natural language approach.

Both languages can access the identical .NET Framework libraries. Both perform largely similarly. In fact, with few exceptions, they perform almost the same assuming VB.NET has Option Strict turned on. Generally, C# is the favorite language of all but die-hard Visual Basic programmers.

The learning curve is steeper for the .NET Framework than for either language. Actually, it would be a simple matter to become fluent in both languages. Nevertheless, there are a few differences between C# and VB .NET as follows:
[edit]
C# advantages

* Explicit interface implementation - an interface implemented in a base class can be reimplemented in a derived class. Of course, this makes the class more obscure in the same way that member hiding does.
* Language support for unsigned types. Unsigned types can be used from VB .NET, but they are not supported by the language itself. This feature is available in VB .NET with Visual Studio 2005.
* Operator overloading. This feature is available in VB.NET with Visual Studio 2005.
* Unsafe code. This allows "pointer arithmetic", etc., and may improve performance in some situations. But, unsafe code circumvents most of the normal safety of features of C#. However, unsafe code is still managed code in a sense, i.e. it is compiled to IL, JITted, and run within the Common Language Runtime (CLR).
* using statement which makes unmanaged resource disposal simple. (Available in VB.NET with Visual Studio 2005.)
* Volatile variables.
* XML documentation generated from source code comments. This feature is available in VB.NET with Visual Studio 2005.

[edit]
Visual Basic.NET advantages

* Catch-When clauses allow exception filtering based upon runtime expressions in addition to by type.
* Late binding with Option Strict off makes legacy libraries without strongly typed interfaces easier to use; but, compile-time, type safety is not available.
* Named indexers - parameterized properties.
* Optional parameters - sometimes useful for COM interoperability
* Simpler event handling in which a method can declare that it handles an event instead of the handler being set up by code.
* Changing method names when implementing interfaces can cause readability and maintenance problems.
* Source code is compiled in the background by the VB.NET part of Visual Studio .NET. Unfortunately, Visual Studio slows down significantly as projects grow larger.
* Legacy Visual Basic functions - The Microsoft.VisualBasic namespace provides various legacy methods which can be used by other .NET languages using a reference to Microsoft.VisualBasic.dll. However, such methods can be detrimental to performance. Therefore, use them wisely or, perhaps, not at all. Readability is also a factor. The use of VB functions may make the source code easier to read for an old-time VB programmer. But, the code will be harder to read for a programmer trained in other .NET languages.

No comments: