Web Design that taps into the haromny and vision of your dreams.

The C# vs Visual Basic Question

C# or Visual Basic, which One is best?

Written By on in C#

1,070 words, estimated reading time 5 minutes.

In this article, we will discuss the various languages available to us in the .Net platform, and why we consider C# to be the best choice.

Introduction to the .Net Framework Series
  1. What is Microsoft .Net?
  2. Benefits of using the .Net Framework
  3. Languages in the .Net Framework
  4. The C# vs Visual Basic Question
  5. Common Language Runtime
  6. The .Net Common Language Specifications
  7. Global Assembly Cache (GAC)

This article relates to an old version of the .Net Framework. While the contents are still relevant, future versions of the framework may change, or improve upon, the contents of this article.

There is much debate in the .Net community over which is better... C# vs VB. There is no clear-cut answer any more as both languages differ only by syntax and a few minor features. If you have done a lot of Visual Basic in the past, you may wish to continue to utilise your existing knowledge and progress to Visual Basic .Net. You may also want to expand your knowledge and learn C#, or vice versa. You may also be new to programming and unable to decide between the two languages.

Whatever the cause of your un-decidedness, hopefully, this article will point out the strengths and weaknesses of the two languages and help you to decide.

Also, bear in mind that there are other programming languages that support the .Net framework. These include C++, Delphi and Perl. This page only discusses Visual Basic .Net and C#.

A Brief History of Visual Basic

Visual Basic came into being in 1991, which was Microsoft's approach to combining a visual development tool with API coding. Originally designated Ruby, and intended for use as a shell for Windows 3.0, it was dropped in favour of the Program Manager. Ruby was used as the visual interface of Visual Basic 1. Visual Basic for DOS was derived from Microsoft's existing QuickBasic compiler.

VB 2 followed a year later and VB 3 in 1993. In each new version the code was reworked to improve performance and by VB 4 class modules were introduced. VB 4 was the first version to support true 32-bit programming, and the ability to write non-GUI (Graphical User Interface).

In 1997 version 5 was released and only offered 32-bit programming. The code could be converted between 4 and 5 for 16-bit applications.

Visual Basic 6 was the keystone version and launched Microsoft's Visual Development environment along with Visual C++. VB6 also allows the development of Web applications.

Visual Basic .Net has been reworked again to take advantage of the .Net framework. It has also been improved to fully support classes and class inheritance for the first time.

One of the biggest disadvantages of Visual Basic prior to .Net was that it was not a structured programming language, and allowed the use of the goto keyword among other non-structured 'features'.

A Brief History of C and C++

The C programming language was invented by Bell Labs in 1972 for use with the Unix operating system. C is block level, structured language that enforces good programming practice, however, the code was messy and poor programming standards would create unstable programs that could crash the mainframe.

C has been transported to multiple platforms and has formed the basis for many programming languages such as C++ in 1979.

C++

With the introduction of C++ came classes, object inheritance, polymorphism and all the other features of a modern object-orientated programming language. C++ as a language has remained unchanged until the introduction of Visual C++ in 1992.

A Little Known Fact About C++

Why is C++ called C++ and not C version 2? Well in the C language, C = C + 1 (i.e. 2) can be simplified with the increment operator (++) so it becomes C++. This is a geeky way of incrementing the version number.

C#

C# (pronounced C Sharp) is a new revision of the C language introduced by Microsoft in 2001 for the brand new .Net Framework. C# is a procedural object orientated language heavily based on C++ with features derived from other programming languages such as Borland Delphi and Java. Microsoft placed a huge emphasis on simplification when they developed the C# language. It is now no longer a messy code, and the framework removes a lot of the issues introduced by sloppy programming by using a managed environment.

Comparison

So which language should you choose? VB.Net and C# are both very stable languages with a good following in the programming community.

Performance

In the past, Visual Basic was an interpreted language, so even though the code was compiled into an executable, it is not native code. As such, Visual Basic Applications tended to run a lot slower than those written in C/C++ that compiled directly to native machine code.

On the .Net platform both C# and Visual Basic are compiled to Microsoft Intermediate Language, which is distributed to client machines and loaded into the CLR. The performance of C# and Visual Basic should be the same.

Readability and Structure

C and C++ are inherently less readable than Visual Basic and Delphi as they use braces, weird operators (if you are unfamiliar with them) and various scope keywords. Visual Basic and Delphi are a lot more verbose in the way methods and variables are declared, as well as how methods are overloaded and inherited.

Example C#

public int myMethod(int x, int y)
{
  return x * y;
}

Visual Basic:

Sub myMethod(int x, int y)
  myMethod = x * y
End Sub

Delphi / Pascal

function myMethod(integer x, integer y): integer
begin
  result := x * y;
end;

Features

Again, there is not a lot of differences between the languages; however, there are features in C# which VB does not support and vice versa.

Features of Visual Basic not supported in C#

  • Optional Parameters can be used in VB.
  • Named Indexers.
  • Optionally ignore ref/ByRef behaviour for passing arguments.
  • With keyword was dropped in C# to enhance readability and to continue with the C++ heritage.
  • Select allows the use of expressions in VB.
  • Handles keyword for wiring of events.

Features of C# not supported in Visual Basic

  • unsafe keyword improves performance by eliminating CLR checking.
  • Iterators
  • Multi-line comments (/* */)
  • Static Classes

Conclusion

We like C# as it is most compatible with existing knowledge, and we feel that the code is neater, more compact and is more readable than that of Visual Basic. We also have an existing code base that is easier to convert to C# than it would be to convert to Visual Basic.

If you have not done any programming at all in the past, Visual Basic has the less steep learning curve, if you are already comfortable with object orientated, C++, Pascal, Delphi or PHP then C# does not have a very steep learning curve.

At the end of the day, however, there is not a great difference between the languages, so the best language to use is the one you are most comfortable with!

Last updated on: Friday 23rd June 2017

 

Comments

There are no comments for this post. Be the first!

 

Leave a Reply

Your email address will not be published.





If you find something abusive or that does not comply with our terms or guidelines please flag it as inappropriate.

Copyright © 2001-2018 Tim Trott, all rights reserved. Web Design by Azulia Designs

This web page is licensed for your personal, private, non-commercial use only.

Disclaimer, Privacy & LegalSitemapContact Me