Are there any INTRINSIC advantages of the C# language over VB.NET?

B

Bob Rosen

I have used VB.NET for several months. Just recently I was asked to modify
some web pages that were developed with C#. Although I know that C# is much
more popular, in comparing the two all of the advantages that I have come
across so far lie on the VB side (correct me if I'm wrong about any of
these; I'm still relatively new to C#):

1. VB supports named arguments (a significant readability advantage if used
properly), C# does not.
2. VB supports optional arguments, C# does not.
3. The C# "switch" statement requires you to explicitly jump out of each
case; if you don't, execution falls into the next case; this substantially
increases the risk of bugs. VB automatically exits its case statement after
executing the case (you can attach multiple conditions to each case.)
4. When you have a series of terminating braces in C#, it can be hard to
figure out exactly what constuct each brace is terminating. With VB, you
can at least say "end if", "end sub", etc., which makes it easier.

The one advantage I know about with C# is that it does a much better job at
getting you employed.

Can anyone come up with advantages of the C# language (compared with VB.NET)
that are inherent in the language? (Note: if you say "it lets me make the
code more compact", shame on you.)

Robert Rosen
 
B

Barry Kelly

Bob Rosen said:
I have used VB.NET for several months. Just recently I was asked to modify
some web pages that were developed with C#. Although I know that C# is much
more popular, in comparing the two all of the advantages that I have come
across so far lie on the VB side (correct me if I'm wrong about any of
these; I'm still relatively new to C#):

1. VB supports named arguments (a significant readability advantage if used
properly), C# does not.
2. VB supports optional arguments, C# does not.

C# uses overloads to provide fulfill similar requirements.
3. The C# "switch" statement requires you to explicitly jump out of each
case; if you don't, execution falls into the next case;

You are thinking of C and C++. This is not the case with C# - you cannot
fall through. The compile generates an error if your case block ends
with something other than break, return, throw or goto on all possible
branches.
4. When you have a series of terminating braces in C#, it can be hard to
figure out exactly what constuct each brace is terminating. With VB, you
can at least say "end if", "end sub", etc., which makes it easier.

The one advantage I know about with C# is that it does a much better job at
getting you employed.

That alone can be a reason to write code in C# - easier to find
maintenance programmers etc.
Can anyone come up with advantages of the C# language (compared with VB.NET)
that are inherent in the language? (Note: if you say "it lets me make the
code more compact", shame on you.)

OK. Since I'm not too familiar with VB, I'll stick with things that I'm
pretty certain aren't in VB.

1) Anonymous delegates:

List<int> x = new List<int>();
x.AddRange(new int[] { 5, 4, 2, 8, 6 }); // what's the syntax for
// this in VB? I don't
// recall.
x.ForEach(Console.WriteLine); // I'm sure VB can do this one.
// Here's the anonymous delegate.
x.ForEach(delegate(int x)
{
Console.WriteLine(x);
});

Anonymous delegates basically make higher-order functional programming a
whole lot easier, for problems that are suitable to a functional
approach. I personally find it extremely painful to program in a
language without them. Killer feature: they can capture variables from
the declaring scope and make them live as long as the delegate does. You
may know the same feature from JavaScript as the function keyword in an
expression context: 'var f = function { /* ... */ };'.

2) Iterators:

class C
{
public static IEnumerable<int> GetInts()
{
int i = 0;
for (;;)
yield return i++;
}
}

Many things that can be logically collections but not actually all
physically co-located in some array somewhere, such that writing a
manual enumerator would be burdensome, can be exposed easily with this
tool. Also, iterators can be used for other interesting things,
especially combinatorial problems.

+ "Advanced Programming Language Design" by Raphael Finkel, chapter 2,
has some examples written in CLU - the source of the iterator idea for
C#. Finkel uses it to generate all possible binary trees of a given
depth. It's remarkably brief.

+ Wesner Moise used iterators to emulate Prolog's searching and clause
resolution:

http://wesnerm.blogs.com/net_undocumented/2005/12/iterators_and_n.html

3) Unsafe code, when it's required (which isn't often at all, but I've
used it where necessary, and it improved performance 3-10x or so
depending on input).

-- Barry
 
C

Cor Ligthert [MVP]

Bob,

All the program languages in Visual Studio make almost the same code. You
can see that if you use a wizard, there is other symbol code generated, but
the performance or whatever from the result is almost the same. (There is no
winner for all situations).

The employing section probably still exist, but I have read somewhere that a
C# MVP could not get a job, so he worked a while as VB developer. The
majority of the companies using classic VB have very big applications
running (and VB is the most used programming language), they have waited to
go to the next version. Now that the most (not on facts based) rant about
VB.Net is gone, there is more chance that it will be VB, which needs endless
amounts of developers.

There are minor differences: C# has more for mathematical programming, while
VB has more for RAD.

For the rest, it is just a matter of preference and because I am certainly
an Alpha; probably therefore I do like VB more. (While I find C# as well a
very nice programming language). Both are in my idea certainly on another
level than most languages from before that time.

Just my thought,

Cor
 
B

Barry Kelly

Cor Ligthert said:
For the rest, it is just a matter of preference and because I am certainly
an Alpha; probably therefore I do like VB more.

What's an Alpha, and why does it imply liking VB?

-- Barry
 
C

Cor Ligthert [MVP]

Barry,

I don't know in which cultures an Alpha and a Betha have meanings, I know
that it is beside mine in more.

An Alpha is in those cultures more biased on telling things with words a
Betha has more with mathemetics.

Cor
 
B

Barry Kelly

Cor Ligthert said:
I don't know in which cultures an Alpha and a Betha have meanings, I know
that it is beside mine in more.

An Alpha is in those cultures more biased on telling things with words a
Betha has more with mathemetics.

OK. I don't know of any better phrases in English other than
language-oriented and math-oriented. It could have been mistaken for
meaning the Alpha in 'alpha-male gorilla', i.e. elite, top-dog.

-- Barry
 
C

Chris Mullins

Can anyone come up with advantages of the C# language (compared with
VB.NET) that are inherent in the language?

I do quite a bit of work in both, and find the two languages to be largley
identical.

There are two things that push me to C#:
1 - The compiler warnings are better. Unused function, methods that forgot
to return values, and such are caught by the C# compiler. The VB.Net 2.0
compiler does a little bit of this, but in general I think C# does a much
better job. You can eliminate this by using FxCop, which does a great job on
both (or any CLR) language.

2 - Samples on the Web tend to be in C#. This means more cut-paste, and
less, cut-paste-PortToVB.
 
M

Mike Lowery

Chris Mullins said:
2 - Samples on the Web tend to be in C#. This means more cut-paste, and less,
cut-paste-PortToVB.

Not just the web; many examples in Visual Studio's own online help only show C#
code. Odd considering VB is more popular.

One of the main advantages of C# for some is that the learning curve is much
smaller for those with a C/C++ background, which is a large audience indeed.
But then the question becomes: why choose C# over C++?
 
B

Barry Kelly

Mike Lowery said:
One of the main advantages of C# for some is that the learning curve is much
smaller for those with a C/C++ background, which is a large audience indeed.
But then the question becomes: why choose C# over C++?

C++ doesn't have all the features of C#, for one thing.

-- Barry
 
B

Brian Gideon

Bob,

Barry already mentioned anonymous methods, but it's worth repeating.
It is a *very* powerful language feature. And that's just a little
teaser to prepare us for lambda expressions in 3.0. VB 9.0 will have
nested functions that allow for closures, but you'll have to wait for
that.

By the way, in the VS editor you can press CTRL-} to automatically
navigate to the closing brace for any code block. The opposite doesn't
seem to work for opening braces though. Anyone know of a shortcut key
to do that?

Brian
 
R

Ron Allen

Brian,
The same key goes both ways, just put the cursor next to the closing
brace and press ctrl+] and it takes you to the opening brace.

Ron Allen
 
B

Brian Gideon

Ron said:
Brian,
The same key goes both ways, just put the cursor next to the closing
brace and press ctrl+] and it takes you to the opening brace.

Yep that works. I'm not sure why I didn't try it before. Thanks for
the tip.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top