VB or C#

  • Thread starter Thread starter Dougie
  • Start date Start date
D

Dougie

I've been learning C# over the past year and don't know too much about VB.
Can anyone describe the advantages VB has over C# or why I should learn VB?
From what I can gather, C# is a better and considered to be a "proper"
programming language. Is this the case?

Doug.
 
* "Dougie said:
I've been learning C# over the past year and don't know too much about VB.
Can anyone describe the advantages VB has over C# or why I should
learn VB?

It's more RAD than C#. The syntax is case-insensitive, so you are
faster because small uppercase/lowercase typos don't cause a compilation
error.
From what I can gather, C# is a better and considered to be a "proper"
programming language. Is this the case?

That's how C* programmers think. For me, VB.NET is a "proper"
programming language, while C# is syntactically "outdated".
 
Dougie said:
I've been learning C# over the past year and don't know too much about VB.
Can anyone describe the advantages VB has over C# or why I should learn VB?
From what I can gather, C# is a better and considered to be a "proper"
programming language. Is this the case?

I'm a C# programmer and I think whoever told you that has NO Clue what they
are talking about. VB.NET 's IDE is much more user friendly. I knew C++ and
Java first, so it's familiar to me, but anyone would have to admit VB.NET is
more friendly to code in.

C# supports unsafe code which is its primary benefit. That may or may not
be an issue, if you need it, you have no chioce.

Also, YOU CAN MIX PROJECTS IN THE SAME SOLUCTION!!!! Yes, you can have them
both there.

If you turn on Option Strict, then performance is virtually identical.

It's a shame people like the one you heard this from speak so
authoritatively when they don't know what they are talking about. As far as
"Proper", there's no difference...
 
Dougie said:
I've been learning C# over the past year and don't know too much
about VB. Can anyone describe the advantages VB has over C# or why I
should learn VB? From what I can gather, C# is a better and
considered to be a "proper" programming language. Is this the case?

Nonsense, VB.NET is just as much a proper language as C# or anything else.
The syntax is very different, personally I like it but that's just me, and
since I come from a BASIC background originally I'm biased. It's case
insensitive for one thing.

As for advantages, their are some. The ones that I like most are:
The WithEvents/Handles event handling syntax:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vakeyhandles.asp

Select Case, which is far more powerful than the C[whatever] switch()
statement:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vaconUsingSelectCase.asp

The Exit (break equivalent) keyword, which allows you to specify what to
exit.
In C derivatives, consider the following:
while( somecondition ) {
for( int x = 0; x < 10; ++x )
{
switch( somevariable ) {
// other cases ommitted
case 5:
// Can't break out of the while loop!
break;
}
}
}

If you want to end the while statement prematurely, you must use break. But
inside the for loop, it exits the for, not the while, and inside the switch
statement, break exits the switch, not the for, let alone the while! So you
can no longer exit the while without some workaround. In VB on the other
hand, you can do this:
While SomeCondition
For X As Integer = 0 To 9
Select Case SomeVariable
' Cases omitted
Case 5
Exit While
End Select
Next
End While

There are other examples, but these spring to mind most.

The biggest advantages of C# over VB.NET are, imo:
Operator overloading
Xml comments
Unsafe code

Operator overloading and xml comments will be added to VB.NET in the Visual
Studio 2005 (codename Whidbey) release.
 
C# (& C/C++) is for those who can't type well and like punctuation marks, VB
is too much like English. Why do I need a 'then' after an 'if' isn't it
obvious? Curly braces are much nicer and I like semicolons and double
backslashes.

Paul
 
Hi Paul,

That "then" I do also not like, however until now it was the only one I
could find in VB.net that is really needed (however I would like it when the
next and loop was one word)

That while C# has a lot of unused (), semicolons, unneeded enclossing of an
If statement, uses the == as a equalcomparer even when it is obvious from
the syntax that it can nothing else than an equalcomparer when = is used.

Is it not a little bit childlike to tell than about that also in my eyes
useless *then* word.

However those who are happy with all those useless characters in C# and
start a discussion here.
I think it is not that much work to make a precompiler for that using
VB.net, which will automaticly correct those needed special characters in C#
when you have not placed them.

Just my thought,

Cor
 
Cor said:
Hi Paul,

That "then" I do also not like, however until now it was the only one
I could find in VB.net that is really needed (however I would like it
when the next and loop was one word)

That while C# has a lot of unused (), semicolons, unneeded enclossing
of an If statement, uses the == as a equalcomparer even when it is
obvious from the syntax that it can nothing else than an
equalcomparer when = is used.

There's no need to get political about this. What kinds of syntax people
like is purely preference and strictly their business. If anything, we need
to be glad these choices exist and we're not forced on one language and one
syntax. So keep your cool everyone. ^_^

And also, the "Then" does serve a purpose. It serves the same purpose as the
() in the C# if statement; seperating the conditional expression from the
statement that comes after it. This is because it is still possible
(although I don't know anyone who does that) to put the following statement
on the same line as the if.
In C# you can say:
if( y == 1 ) y++;
And in VB you can say;
If y = 1 Then y += 1

Without the () or Then the compiler wouldn't be able to tell where the
conditional expression ends and the statement begins.

In good old BASIC (and I mean OLD, as in before Quick Basic, as in MBASIC,
GW-BASIC, MSX-BASIC, the types that required line numbers) there were no
If...End If blocks. If statements had to be one line, and if you wanted to
execute multiple statements after the same if, you either seperated them
using a colon (:) on the same line, or used goto. In those days, "Then" was
the only thing standing between the If and its result. Note that in an act
of equality, the Else also had to be on the same line. Great syntax that
was... ^_^
In those days you could actually put other things than "Then" behind an if.
There were three variants if I remember correctly:
IF Y = 1 THEN Y = Y + 1
IF Y = 1 GOTO 100
IF Y = 1 GOSUB 200

Thankfully the second form isn't allowed anymore, and gosub has long been
burried as it should be.

When using an If...End If block, the Then becomes unnecessary, because the
new line is enough seperation (in C# though you must keep the () *and* add
curly braces, so one could argue that's even worse), but it is kept for the
sake of consistency.

And in all honesty, does it matter? With modern editors like VS.NET you
don't actually have to type it anyway, it is inserted automatically when you
press enter after the conditional expression. So it doesn't matter anyway.
However those who are happy with all those useless characters in C#
and start a discussion here.
I think it is not that much work to make a precompiler for that using
VB.net, which will automaticly correct those needed special
characters in C# when you have not placed them.

Not possible in general, because newline isn't a seperator in C#. If there's
no semicolon, curly brace, () or whatever to seperate things, the statement
just continues on the next line, just as if the newline hadn't been there at
all. Without all those so-called 'useless' characters it becomes possible to
create unparsable constructs where such constructs would be valid when
they're there.
 
Hi Sven

I forget the C# this is not a C# newsgroup however.

If y = 1 Then y += 1

If y = 1 y += 1

What do I miss, when there is an operator behind it (whatever kind) than it
continues.

However seriously maybe I miss something and you can tell me what?

Cor
 
Cor said:
Hi Sven

I forget the C# this is not a C# newsgroup however.

If y = 1 Then y += 1

If y = 1 y += 1

What do I miss, when there is an operator behind it (whatever kind)
than it continues.

I think you maybe right in that it's possible to write a parser that works
that way, at least I can't offhand think of an example where the resulting
parse tree would be ambiguous (which of course doesn't mean there isn't
one). However, I would argue against it with three reasons:
1. It doesn't exactly improve readability. The eye needs seperators too.
(although I don't consider the entire one-line if construction to be very
readable).
2. It introduces a class of errors that could be confusing. If you allow
your example above, and also allow then to be ommitted in the If..End If
constructs, then something really nasty can happen. Consider this example:
If y = 1 x = y + 3
Now the programmer makes the following small typo:
If y = x = y + 3
This would lead to a 'missing end if' error 30 lines down, not very helpful.
3. Having a fixed seperator makes your parser much simpler. Trust me, I've
written compiler parsers, and something like this is not nice to deal with.
It makes the parser more complex, which ultimately means more work for the
parser writers, more chances of bugs in the parser, and a slower parser.
Especially with error productions (that allow the parser to continue after a
single error has been seen) you want that seperator to be there. If it's
not, then a parser error in the expression means you don't know if it's
supposed to be a block or a one-line if, in which case you might end up with
mismatched End Ifs, and a lot of errors in unrelated parts of the code. At
least thanks to the seperate End <something> statements in VB this won't go
too far. Too often have I seen a single forgotten } in C++ lead to
'unexpected end of file found', because everything after that parsed but
missed a } at the end. But I digress.
Compiler writers are people too. They deserve to add things to the language
to make their work simpler once every while. ^_^
 
Hi Sven,

Reasons as work for the builder does in my opinion not count in this case
that is work for one against work for many. That is where the whole IT is
build on.

And it can be optional, just for reading, there are a lot of programming
languages where that is implemented in that way.

Cor
 
* "Paul Fredlein said:
C# (& C/C++) is for those who can't type well and like punctuation marks, VB
is too much like English. Why do I need a 'then' after an 'if' isn't it
obvious? Curly braces are much nicer and I like semicolons and double
backslashes.

In other words: You like ASCII art.
 
* "Cor Ligthert said:
I forget the C# this is not a C# newsgroup however.

If y = 1 Then y += 1

If y = 1 y += 1

What do I miss, when there is an operator behind it (whatever kind) than it
continues.

I consider that to be not "human readable".
 
Herfried,
If y = 1 Then y += 1

I consider that to be not "human readable".

If y = 22
Herfried &= "Should understand this"
End if

Is the normal behaviour, I always forget to type that "then" (I can even
think on a situation as the select where the case comes automaticly)

Cor
 
* "Cor Ligthert said:
If y = 22
Herfried &= "Should understand this"
End if

Is the normal behaviour, I always forget to type that "then" (I can even
think on a situation as the select where the case comes automaticly)

Maybe it's only because I am used to it, but I am visually missing
something in the code above. To identify what code does, I do not only
look at the indentation and the left "edge", but I scan the right "edge"
too. If there is a 'Then', I clearly see that the text left to it must
be part of an 'If...Then', if it isn't, that's harder to decide.
 
Back
Top