F1
About F1Course ScheduleOther ServicesSite MapContactHome

 
.net
Access
Visual FoxPro & foxpro
Visual Studio
SQL
Visual Basic
Other Courses
mcsd.gif (1348 bytes)
nt.gif (1423 bytes)
nt.gif (1423 bytes)
Visual Basic .NET or C#?
by Steve Wilson

Visual Studio.NET allows the programmer to choose from a bewildering range of development languages, but the two main languages hosted by Visual Studio.NET are Visual Basic.NET and C#.  Visual Basic.NET is an evolutionary (some say revolutionary) extension to Visual Basic, and C# is a new language, albeit one with recognisable roots in Java and C++.

So which is the ‘better’ language: VB.NET or C#?

This is one of the more common questions raised by developers migrating to Visual Studio.NET, and a common source of arguments among those who have already made their choice – or had it made for them by their company’s choice of development language.

There is no single, standard answer to the question of which is the better of the two, other than ‘it depends …’.  You should ask yourself a number of searching questions before deciding which language suits you better.

If you’re already a programmer, the first question should be which language can better leverage your existing skill set into the new environment of Visual Studio.NET - or, more simply, what’s your background?  If it’s the Visual Basic language then Visual Basic.NET should be self-recommending; granted there are new concepts to grapple with, such as a true object-orientated programming model and non-deterministic memory management to name only two, but the language is obviously an offshoot from Visual Basic.

If your background lies in C++ or Java, then C# probably involves a less steep learning curve: you may already be using structured exception handling, programming to an object-oriented design pattern, and relying on processes like garbage collection.  There are good reasons to consider learning Visual Basic.NET, but it seems perverse to ignore C#’s debt to the above two object-oriented languages.

However, it’s not just about background. Programmers learn by reading and writing code.  When we consider the resources available to programmers taking up one of the two languages, C# as the more ‘fashionable’ language of the two has probably spawned more sample code than Visual Basic.NET.

The balance is slowly being redressed, but a trawl through some of the major ‘DotNet’ sites on the internet still support the argument that there’s more C# code out there as programmers strut their stuff in the new language.

Another question to ask yourself is how strict do I want my language to be?  Visual Basic.NET allows strong code checks, but the default type checking is ‘Explicit’ rather than ‘Strict’.  On the other side of the equation, C# considers optional parameters and ‘with’ blocks to be dangerous programming precedents, which are steadfastly rejected.

This suggests that Visual Basic.NET is a slightly more ‘relaxed’ programming environment than C#:  Unlike C#, Visual Basic.NET is case-insensitive, and doesn’t require parentheses to be explicitly added to all method invocations.  It could be argued that Visual Basic.NET programmers would have been on the side of the cavaliers in the English Civil War, while C# programmers would have supported the roundheads (Visual Basic.NET as ‘wrong but romantic’).

Some programmers may want to consider the differences between the two languages and choose the one which offers a competitive advantage to coders: more/better tools, increased flexibility, etc.

In reality there are only small differences between the two languages: C# can do some things (operator overloading, handle unsafe code, etc.) that Visual Basic.NET can’t, and Visual Basic.NET can do some stuff that C# doesn’t support (optional parameters, ‘with’ blocks, etc.).

As far as I’m concerned it’s an issue of the heart as well as the head. Setting aside programming background (ten years of Visual Basic experience), logic pulls me towards Visual Basic.NET: I’m slightly more productive in the explicit, case-insensitive environment of Visual Basic .NET than C#.  However I like C#; it doesn’t hold my hand quite as much as does Visual Basic.NET, and it appears to go a tiny bit deeper in some areas
(eg. delegates) than does Visual Basic.NET.

As programmers we should strive to be multilingual, and as a F1 trainer I use and train in both languages.  As long as I don’t have to write code samples in Visual Basic .NET and C# for a mixed group of programmers too often, I’m happy with either language.

So, as you assemble the reasons for choosing or defending one or the other of the two languages, consider learning and using both.  Both languages are supported equally by the common language runtime, and as both compile to exactly the same intermediate language (MSIL), assemblies written in either language interact natively with each other.

You may have a preference for one language over the other; you may have an aversion to a blizzard of curly braces, and a dislike of semi-colons at the end of almost every line of code; you may feel that one language is not as ‘hardcore’ as the other or, conversely that there’s not enough support in one language as in the other.

The truth is it’s a ‘swings and roundabouts’ thing: Visual Basic.NET has better developer support in a couple of crucial areas; most notably code beautification, block completion, and more responsive IntelliSense. Additionally, if you come from a case-insensitive language background, C# will drive you mad.

However C# is a more ‘elegant’ language, unattached to ‘the way things have always been done’.  With better support from the Class Viewer, and the provision of a number of processes that Visual Basic.NET is playing catch-up on, C# has been doing for the last two years what Visual Basic.NET has still to learn.

Striving to be strictly impartial, and considering both the similarities and the differences between the two languages, it’s impossible to come to a fully considered, clear choice between these two languages.  Should the new programmer learn one or the other language?  Is one more of a RAD language than the other?  Which language attracts the wider choice of employment/consultancy opportunities?  The higher salary?  Which language do I reach for automatically?

In the end, to avoid the pitfalls of choosing one of the two languages for the wrong reasons, I’d advise anyone posing the question of which of the two languages is the ‘better’ to choose to learn both languages.  If you do so, you will be a better informed, more productive, and valuable programmer.

Finally, my choice of language is … C# … no, it’s VB.NET … or is it C#? 
It depends.


TOP


© F1 Computing Systems 2004