Celebrity Deathmatch (VB.NET vs C#)
-
There hasn't been a good "why language X sucks and language Y is better" thread in a good while, so I thought I'd start one. Unlike most, however, this one has rules. I will post a reason C# is better than VB.NET and somebody reply with a reason VB.NET is better than C#. I (or somebody else) will then reply to that message stating another reason C# is better. And so on. Also, you must show code examples (when appropriate). I'll start. C# Is Less Verbose
Public Sub Something()
' VB.NET...
End Subpublic void Something()
{
// C#...
}You're turn (post why VB.NET is better than C#). :)
-
There hasn't been a good "why language X sucks and language Y is better" thread in a good while, so I thought I'd start one. Unlike most, however, this one has rules. I will post a reason C# is better than VB.NET and somebody reply with a reason VB.NET is better than C#. I (or somebody else) will then reply to that message stating another reason C# is better. And so on. Also, you must show code examples (when appropriate). I'll start. C# Is Less Verbose
Public Sub Something()
' VB.NET...
End Subpublic void Something()
{
// C#...
}You're turn (post why VB.NET is better than C#). :)
I'll give an example reply as well... VB.NET is Backward Compatible with VB6
On Error GoTo ErrorHandler Throw New Exception("Error!") Return
ErrorHandler:
MessageBox.Show("Darn!")C# does not have this handy backward compatibility, so upgrading from VB6 is more difficult when going to C#.
-
There hasn't been a good "why language X sucks and language Y is better" thread in a good while, so I thought I'd start one. Unlike most, however, this one has rules. I will post a reason C# is better than VB.NET and somebody reply with a reason VB.NET is better than C#. I (or somebody else) will then reply to that message stating another reason C# is better. And so on. Also, you must show code examples (when appropriate). I'll start. C# Is Less Verbose
Public Sub Something()
' VB.NET...
End Subpublic void Something()
{
// C#...
}You're turn (post why VB.NET is better than C#). :)
-
There hasn't been a good "why language X sucks and language Y is better" thread in a good while, so I thought I'd start one. Unlike most, however, this one has rules. I will post a reason C# is better than VB.NET and somebody reply with a reason VB.NET is better than C#. I (or somebody else) will then reply to that message stating another reason C# is better. And so on. Also, you must show code examples (when appropriate). I'll start. C# Is Less Verbose
Public Sub Something()
' VB.NET...
End Subpublic void Something()
{
// C#...
}You're turn (post why VB.NET is better than C#). :)
VB.NET supports by-ref extension methods. As of 4.0, C# does not.
Regards, Nish
Are you addicted to CP? If so, check this out: The Code Project Forum Analyzer : Find out how much of a life you don't have! My technology blog: voidnish.wordpress.com
-
i'm not a vb guy anymore but when i was i LOVED exit on first failed step. ( instead of nested if's )
Select Case False Case Step1() Case Step2() Case Step3() End Select
cant do that in C#
That's pretty neat! But you can actually get pretty close to that in C#:
var steps = new List<Func<bool>> { Step1, Step2, Step3 };
foreach (var step in steps)
{
if (!step()) break;
}And if you create this helper function:
void DoEach(params Func<bool>[] steps)
{
foreach (var step in steps)
{
if (!step()) break;
}
}You can shorten that code even further:
DoEach(new Func<bool>[] {
Step1,
Step2,
Step3
});Got to love delegate inference! Not sure, but I think there's something in LINQ that does something like this as well. Can't be bothered to try and find it now though.
-
That's pretty neat! But you can actually get pretty close to that in C#:
var steps = new List<Func<bool>> { Step1, Step2, Step3 };
foreach (var step in steps)
{
if (!step()) break;
}And if you create this helper function:
void DoEach(params Func<bool>[] steps)
{
foreach (var step in steps)
{
if (!step()) break;
}
}You can shorten that code even further:
DoEach(new Func<bool>[] {
Step1,
Step2,
Step3
});Got to love delegate inference! Not sure, but I think there's something in LINQ that does something like this as well. Can't be bothered to try and find it now though.
The VB Select-Case is more flexible than just that. Example from MSDN:
Dim number As Integer = 8
Select Case number
Case 1 To 5
Debug.WriteLine("Between 1 and 5, inclusive")
' The following is the only Case clause that evaluates to True.
Case 6, 7, 8
Debug.WriteLine("Between 6 and 8, inclusive")
Case 9 To 10
Debug.WriteLine("Equal to 9 or 10")
Case Else
Debug.WriteLine("Not between 1 and 10, inclusive")
End SelectRegards, Nish
Are you addicted to CP? If so, check this out: The Code Project Forum Analyzer : Find out how much of a life you don't have! My technology blog: voidnish.wordpress.com
-
VB.NET supports by-ref extension methods. As of 4.0, C# does not.
Regards, Nish
Are you addicted to CP? If so, check this out: The Code Project Forum Analyzer : Find out how much of a life you don't have! My technology blog: voidnish.wordpress.com
You broke a rule. You didn't post sample code. I'm not sure you are correct, and without sample code I can't be bothered to verify. :(
-
You broke a rule. You didn't post sample code. I'm not sure you are correct, and without sample code I can't be bothered to verify. :(
Oh sorry, it's so well known that I didn't think you'd need code to back it up :-) See this blog post: http://blog.gadodia.net/extension-methods-in-vbnet-and-c/[^]
Regards, Nish
Are you addicted to CP? If so, check this out: The Code Project Forum Analyzer : Find out how much of a life you don't have! My technology blog: voidnish.wordpress.com
-
That's pretty neat! But you can actually get pretty close to that in C#:
var steps = new List<Func<bool>> { Step1, Step2, Step3 };
foreach (var step in steps)
{
if (!step()) break;
}And if you create this helper function:
void DoEach(params Func<bool>[] steps)
{
foreach (var step in steps)
{
if (!step()) break;
}
}You can shorten that code even further:
DoEach(new Func<bool>[] {
Step1,
Step2,
Step3
});Got to love delegate inference! Not sure, but I think there's something in LINQ that does something like this as well. Can't be bothered to try and find it now though.
this would be a linq version
(from f in new List<Func<bool>>() { Step1, Step2, Step3 } where !f() select 0).FirstOrDefault();
but you are still limited to the same function signature in the vb version it could be
case step1(mystring)
case step2(myint, mystring)
.....modified on Monday, March 28, 2011 6:56 PM
-
VB.NET supports by-ref extension methods. As of 4.0, C# does not.
Regards, Nish
Are you addicted to CP? If so, check this out: The Code Project Forum Analyzer : Find out how much of a life you don't have! My technology blog: voidnish.wordpress.com
meh. enum = enum.fromString("foo") suffices.
If your actions inspire others to dream more, learn more, do more and become more, you are a leader." - John Quincy Adams
You must accept one of two basic premises: Either we are alone in the universe, or we are not alone in the universe. And either way, the implications are staggering” - Wernher von Braun -
There hasn't been a good "why language X sucks and language Y is better" thread in a good while, so I thought I'd start one. Unlike most, however, this one has rules. I will post a reason C# is better than VB.NET and somebody reply with a reason VB.NET is better than C#. I (or somebody else) will then reply to that message stating another reason C# is better. And so on. Also, you must show code examples (when appropriate). I'll start. C# Is Less Verbose
Public Sub Something()
' VB.NET...
End Subpublic void Something()
{
// C#...
}You're turn (post why VB.NET is better than C#). :)
AspDotNetDev wrote:
C# Is Less Verbose
Not really. Like all C-based languages, C# requires symbols that are of no use either to compiler or humans who read the code. In the example above, the meaning of
Sub
andEnd Sub
is far clearer than{
and}
. That kind of "verbosity" is good. Truly expressive languages are for instance ones from ML family. Still too much syntax, but much cleaner and much less unneeded symbols than C/C++/Java/C# -
this would be a linq version
(from f in new List<Func<bool>>() { Step1, Step2, Step3 } where !f() select 0).FirstOrDefault();
but you are still limited to the same function signature in the vb version it could be
case step1(mystring)
case step2(myint, mystring)
.....modified on Monday, March 28, 2011 6:56 PM
cechode wrote:
but you are still limited to the same function signature
Lambdas + delegate inference:
DoEach(new Func<bool>[]
{
Step1,
() => Step2(5)
});:-D
-
Oh sorry, it's so well known that I didn't think you'd need code to back it up :-) See this blog post: http://blog.gadodia.net/extension-methods-in-vbnet-and-c/[^]
Regards, Nish
Are you addicted to CP? If so, check this out: The Code Project Forum Analyzer : Find out how much of a life you don't have! My technology blog: voidnish.wordpress.com
You are right, it does not support passing the primary variable by reference. However, the other parameters can be passed by reference (this is what I thought you were initially claiming could not be done). One could workaround that by passing the primary variable through a second parameter by reference. Still, that's not as nice as VB.NET's implementation.
-
AspDotNetDev wrote:
C# Is Less Verbose
Not really. Like all C-based languages, C# requires symbols that are of no use either to compiler or humans who read the code. In the example above, the meaning of
Sub
andEnd Sub
is far clearer than{
and}
. That kind of "verbosity" is good. Truly expressive languages are for instance ones from ML family. Still too much syntax, but much cleaner and much less unneeded symbols than C/C++/Java/C#Perhaps I should have said "C# Is More Concise". :rolleyes: But kudos to you for bringing up the counter point that VB.NET is more expressive. I think, however, that it's expressive in areas which do not require expressiveness. Maybe "End Sub" makes the code easier to read to somebody not initiated with the language, but it doesn't make the code any easier to write (you would have to know the "End Sub" in advance, so it's not expressing anything until you write it yourself). Of course, intellisense adds "End Whatever" for you, which brings me to my counter point: If-Statements Are Easier To Type in C# Supposing you have a code block and you want to surround it with an if-statement. In VB.NET, you must type "End If" in full:
If True Then
' Code Block.If you press ENTER after "Then", the "End If" will be added in the wrong place. Instead, you can go to the bottom of the code block and type "End If". In C#:
if (true)
{
// Code Block.All you have to type is "}" and the code auto-indents nicely. Along those same lines, C# waits until you type the closing brace... VB.NET is a little eager and indents the code before you need it to.
-
Perhaps I should have said "C# Is More Concise". :rolleyes: But kudos to you for bringing up the counter point that VB.NET is more expressive. I think, however, that it's expressive in areas which do not require expressiveness. Maybe "End Sub" makes the code easier to read to somebody not initiated with the language, but it doesn't make the code any easier to write (you would have to know the "End Sub" in advance, so it's not expressing anything until you write it yourself). Of course, intellisense adds "End Whatever" for you, which brings me to my counter point: If-Statements Are Easier To Type in C# Supposing you have a code block and you want to surround it with an if-statement. In VB.NET, you must type "End If" in full:
If True Then
' Code Block.If you press ENTER after "Then", the "End If" will be added in the wrong place. Instead, you can go to the bottom of the code block and type "End If". In C#:
if (true)
{
// Code Block.All you have to type is "}" and the code auto-indents nicely. Along those same lines, C# waits until you type the closing brace... VB.NET is a little eager and indents the code before you need it to.
AspDotNetDev wrote:
VB.NET is a little eager and indents the code before you need it to.
Seems more like an IDE quirk than a language quirk...
Reminiscing just isn't what it used to be!! If you like cars, check out the Booger Mobile blog | If you feel generous - make a donation to Camp Quality!!
-
AspDotNetDev wrote:
VB.NET is a little eager and indents the code before you need it to.
Seems more like an IDE quirk than a language quirk...
Reminiscing just isn't what it used to be!! If you like cars, check out the Booger Mobile blog | If you feel generous - make a donation to Camp Quality!!
Indeed. Visual Studio has VB.NET Quirks [see above] Better? :rolleyes:
-
The VB Select-Case is more flexible than just that. Example from MSDN:
Dim number As Integer = 8
Select Case number
Case 1 To 5
Debug.WriteLine("Between 1 and 5, inclusive")
' The following is the only Case clause that evaluates to True.
Case 6, 7, 8
Debug.WriteLine("Between 6 and 8, inclusive")
Case 9 To 10
Debug.WriteLine("Equal to 9 or 10")
Case Else
Debug.WriteLine("Not between 1 and 10, inclusive")
End SelectRegards, Nish
Are you addicted to CP? If so, check this out: The Code Project Forum Analyzer : Find out how much of a life you don't have! My technology blog: voidnish.wordpress.com
I do like that about VB.NET. That would be nice if they added it to C#.
-
Perhaps I should have said "C# Is More Concise". :rolleyes: But kudos to you for bringing up the counter point that VB.NET is more expressive. I think, however, that it's expressive in areas which do not require expressiveness. Maybe "End Sub" makes the code easier to read to somebody not initiated with the language, but it doesn't make the code any easier to write (you would have to know the "End Sub" in advance, so it's not expressing anything until you write it yourself). Of course, intellisense adds "End Whatever" for you, which brings me to my counter point: If-Statements Are Easier To Type in C# Supposing you have a code block and you want to surround it with an if-statement. In VB.NET, you must type "End If" in full:
If True Then
' Code Block.If you press ENTER after "Then", the "End If" will be added in the wrong place. Instead, you can go to the bottom of the code block and type "End If". In C#:
if (true)
{
// Code Block.All you have to type is "}" and the code auto-indents nicely. Along those same lines, C# waits until you type the closing brace... VB.NET is a little eager and indents the code before you need it to.
AspDotNetDev wrote:
Maybe "End Sub" makes the code easier to read to somebody not initiated with the language, but it doesn't make the code any easier to write
Which is a reasonable trade-off. You write code once and read it many times. Besides, with any decent editor, it is a non-issue.
AspDotNetDev wrote:
if (true)
{I see unnecessary and confusing symbols here. For instance in Go, it would be something like:
if true {
Or (even better) in ML:
if true then
-
AspDotNetDev wrote:
Maybe "End Sub" makes the code easier to read to somebody not initiated with the language, but it doesn't make the code any easier to write
Which is a reasonable trade-off. You write code once and read it many times. Besides, with any decent editor, it is a non-issue.
AspDotNetDev wrote:
if (true)
{I see unnecessary and confusing symbols here. For instance in Go, it would be something like:
if true {
Or (even better) in ML:
if true then
Nemanja Trifunovic wrote:
You write code once and read it many times.
By that same reasoning, you learn a language once (well, can take a while for things to sink in) and you can develop software for many years based on that knowledge. It is faster to read "{}" than "Then End If", so why not go for the faster version since it is the one that will lead to the least overall time spent reading if-statements?
-
Indeed. Visual Studio has VB.NET Quirks [see above] Better? :rolleyes:
AspDotNetDev wrote:
Visual Studio has VB.NET Quirks
Oh, Zarquon, no... VS' VB editor keeps deleting stuff; I have to be very careful when I do certain things. I'd give a example, but the wife says that dinner is ready.