Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. Celebrity Deathmatch (VB.NET vs C#)

Celebrity Deathmatch (VB.NET vs C#)

Scheduled Pinned Locked Moved The Lounge
csharphtmlcssvisual-studio
80 Posts 24 Posters 64 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A AspDotNetDev

    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 Sub

    public void Something()
    {
    // C#...
    }

    You're turn (post why VB.NET is better than C#). :)

    [WikiLeaks Cablegate Cables]

    S Offline
    S Offline
    Smohd5
    wrote on last edited by
    #55

    Your code snippet shows they are equal because the code are generated by the IDE

    A 1 Reply Last reply
    0
    • C coding4ever

      AspDotNetDev wrote:

      VB.NET is Backward Compatible with VB6

      And this is supposed to be a good thing? ;P Though I will give you props for actually using an ErrorHandler and not simply going with On Error Resume Next like my predecessor did.

      S Offline
      S Offline
      Sterling Camden independent consultant
      wrote on last edited by
      #56

      And actually, it isn't. Migrating VB6 code to VB.NET can be a royal pain, and usually ends up as a rewrite (in C#).

      Contains coding, but not narcotic.

      1 Reply Last reply
      0
      • A AspDotNetDev

        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#.

        [WikiLeaks Cablegate Cables]

        P Offline
        P Offline
        programmervb netc
        wrote on last edited by
        #57

        He said post something that makes it better just kidding. Humble Programmer

        1 Reply Last reply
        0
        • T the Kris

          This can much shorter! Step1() && Step2() && Step3();

          A Offline
          A Offline
          AspDotNetDev
          wrote on last edited by
          #58

          True, but it can only be used with a boolean value. The others can work with non-boolean values.

          [WikiLeaks Cablegate Cables]

          T 1 Reply Last reply
          0
          • F frattaro

            Ever tried writing dynamic (X/HT)ML?

            Dim header =

            <%= publicationdate %>

            That's a lot easier than anything in C#. Stringbuilders, XMLwriters, whatever... doesn't beat VB.NET's XML Literals.

            A Offline
            A Offline
            AspDotNetDev
            wrote on last edited by
            #59

            Yeah, that is nice.

            [WikiLeaks Cablegate Cables]

            1 Reply Last reply
            0
            • S Smohd5

              Your code snippet shows they are equal because the code are generated by the IDE

              A Offline
              A Offline
              AspDotNetDev
              wrote on last edited by
              #60

              Huh? Did you reply to the right message? I don't know what you mean.

              [WikiLeaks Cablegate Cables]

              1 Reply Last reply
              0
              • A AspDotNetDev

                True, but it can only be used with a boolean value. The others can work with non-boolean values.

                [WikiLeaks Cablegate Cables]

                T Offline
                T Offline
                the Kris
                wrote on last edited by
                #61

                Does Func<bool> accept non-bool funcs? If not the other C# examples here only accept bool too. Or am I missing the point here?

                A 1 Reply Last reply
                0
                • T the Kris

                  Does Func<bool> accept non-bool funcs? If not the other C# examples here only accept bool too. Or am I missing the point here?

                  A Offline
                  A Offline
                  AspDotNetDev
                  wrote on last edited by
                  #62

                  See the tip/trick I just posted. You don't have to use Func<bool>. You can use whatever return type you need. You can even use Func<Object> if you like. I'm not sure, but I think covariance or contravariance (I forget which is which) may allow you to still avoid having to wrap the functions in a new lambda.

                  [WikiLeaks Cablegate Cables]

                  1 Reply Last reply
                  0
                  • N Nemanja Trifunovic

                    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

                    utf8-cpp

                    K Offline
                    K Offline
                    Klaus Werner Konrad
                    wrote on last edited by
                    #63

                    #define then {

                    1 Reply Last reply
                    0
                    • T the Kris

                      This can much shorter! Step1() && Step2() && Step3();

                      K Offline
                      K Offline
                      KP Lee
                      wrote on last edited by
                      #64

                      Yes, it can, but you want the process to complete each routine until it reaches a true condition, so your code has a bug in it (correct version): static void Main(string[] args) { bool s = !step1() && !step2() && !step3(); Console.Read(); } static bool step1() { Console.WriteLine("Step 1"); return false; } static bool step2() { Console.WriteLine("Step 2"); return true; } static bool step3() { Console.WriteLine("Step 3"); return false; }

                      T 1 Reply Last reply
                      0
                      • K KP Lee

                        Yes, it can, but you want the process to complete each routine until it reaches a true condition, so your code has a bug in it (correct version): static void Main(string[] args) { bool s = !step1() && !step2() && !step3(); Console.Read(); } static bool step1() { Console.WriteLine("Step 1"); return false; } static bool step2() { Console.WriteLine("Step 2"); return true; } static bool step3() { Console.WriteLine("Step 3"); return false; }

                        T Offline
                        T Offline
                        the Kris
                        wrote on last edited by
                        #65

                        Nope, 'cechode' wrote: General Re: Celebrity Deathmatch (VB.NET vs C#) Pin member cechode 23hrs 30mins ago i'm not a vb guy anymore but when i was i LOVED exit on first failed step. ( instead of nested if's ) BTW, I would use bool s = step1() || step2() || step3(); to execute until first true result.

                        K 1 Reply Last reply
                        0
                        • N Nish Nishant

                          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

                          K Offline
                          K Offline
                          KP Lee
                          wrote on last edited by
                          #66

                          Nishant Sivakumar wrote:

                          VB.NET supports by-ref extension methods. As of 4.0, C# does not.

                          WHAT!!! I don't have 4.0 version. This continues to work in 3.5: void step1(ref int x)... Are you saying all legacy C# code that uses that convention is now broken in 4.0, or did I misunderstand what you said? One thing I do have to do in 3.5 is initialize the int variable's value being passed. (Unless I use out instead of ref.) Something is rather goofy in VB.NET, I can pass a referential object as a by val field if I want. (It, of course, remains by ref.)

                          N 1 Reply Last reply
                          0
                          • A AspDotNetDev

                            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 Sub

                            public void Something()
                            {
                            // C#...
                            }

                            You're turn (post why VB.NET is better than C#). :)

                            [WikiLeaks Cablegate Cables]

                            X Offline
                            X Offline
                            xympa
                            wrote on last edited by
                            #67

                            in C#:

                            i_can_do_this(); and_this(); //in the same line

                            Because of the delimeter, sometimes it makes sense not to waste one line and make the code more readable, especially when assigning multiple variables in the same context. -- Turns out you can do it in VB with ":" check the reply bellow.

                            modified on Tuesday, March 29, 2011 7:11 PM

                            O K 2 Replies Last reply
                            0
                            • A AspDotNetDev

                              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.

                              [WikiLeaks Cablegate Cables]

                              K Offline
                              K Offline
                              KP Lee
                              wrote on last edited by
                              #68

                              Now you are getting into intellisense (mis-)behavior. The difference in code behavior is basically C#: unless I tell you different, the next line is part of the same command VB: unless I tell you different, the next line is NOT part of the same command. "If" is one of those awkward step children that don't follow that rule very well. I agree with you, there is generally more typing in VB than in C#, whether or not you use VS to build your code. If I remember VB.NET correctly, you type If... and carriage return, it doesn't place the End If incorrectly, just awkwardly in relation to your cursor position and the commands you want to enter into the block.

                              1 Reply Last reply
                              0
                              • A AspDotNetDev

                                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 Sub

                                public void Something()
                                {
                                // C#...
                                }

                                You're turn (post why VB.NET is better than C#). :)

                                [WikiLeaks Cablegate Cables]

                                O Offline
                                O Offline
                                obermd
                                wrote on last edited by
                                #69

                                VB has Explicit Event handlers VB:

                                Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

                                End Sub
                                

                                C#:

                                private void Form1_Load(object sender, EventArgs e)

                                    {
                                
                                    }
                                

                                This comes in real handy when you need the same event to handle multiple controls on a form.

                                Mike

                                K A 2 Replies Last reply
                                0
                                • M Michael Kingsford Gray

                                  VB is better because I use it more often, and have more experience with it than C#. Do I get points for honesty?

                                  K Offline
                                  K Offline
                                  KP Lee
                                  wrote on last edited by
                                  #70

                                  Michael K Gray wrote:

                                  Do I get points for honesty?

                                  I don't think so, at least in the rules set out. The rules kind of limit the playing field to people who have a fairly good knowledge of both. The fact that you can turn out code more quickly (and I assume accurately) in VB is offset by those who can say the same about C#. I wouldn't worry about it, this battle is all tongue-in-cheek(TIC). Your point just reinforces that everything said here has to be TIC.

                                  1 Reply Last reply
                                  0
                                  • X xympa

                                    in C#:

                                    i_can_do_this(); and_this(); //in the same line

                                    Because of the delimeter, sometimes it makes sense not to waste one line and make the code more readable, especially when assigning multiple variables in the same context. -- Turns out you can do it in VB with ":" check the reply bellow.

                                    modified on Tuesday, March 29, 2011 7:11 PM

                                    O Offline
                                    O Offline
                                    obermd
                                    wrote on last edited by
                                    #71

                                    VB has a ":" colon to seperate multiple statements in the same line. statement1 : statement2

                                    Mike

                                    X 1 Reply Last reply
                                    0
                                    • O obermd

                                      VB has a ":" colon to seperate multiple statements in the same line. statement1 : statement2

                                      Mike

                                      X Offline
                                      X Offline
                                      xympa
                                      wrote on last edited by
                                      #72

                                      I did not know that, thank you for correcting me, i don't use VB much ^^ feel free to downrate my comment.

                                      1 Reply Last reply
                                      0
                                      • X xympa

                                        in C#:

                                        i_can_do_this(); and_this(); //in the same line

                                        Because of the delimeter, sometimes it makes sense not to waste one line and make the code more readable, especially when assigning multiple variables in the same context. -- Turns out you can do it in VB with ":" check the reply bellow.

                                        modified on Tuesday, March 29, 2011 7:11 PM

                                        K Offline
                                        K Offline
                                        KP Lee
                                        wrote on last edited by
                                        #73

                                        i_can_do_this(); and_this(); /*in the same line*/and_thistoo(); Try that with //!!!

                                        1 Reply Last reply
                                        0
                                        • K KP Lee

                                          Nishant Sivakumar wrote:

                                          VB.NET supports by-ref extension methods. As of 4.0, C# does not.

                                          WHAT!!! I don't have 4.0 version. This continues to work in 3.5: void step1(ref int x)... Are you saying all legacy C# code that uses that convention is now broken in 4.0, or did I misunderstand what you said? One thing I do have to do in 3.5 is initialize the int variable's value being passed. (Unless I use out instead of ref.) Something is rather goofy in VB.NET, I can pass a referential object as a by val field if I want. (It, of course, remains by ref.)

                                          N Offline
                                          N Offline
                                          Nish Nishant
                                          wrote on last edited by
                                          #74

                                          KP Lee wrote:

                                          WHAT!!!
                                          I don't have 4.0 version. This continues to work in 3.5: void step1(ref int x)...
                                          Are you saying all legacy C# code that uses that convention is now broken in 4.0, or did I misunderstand what you said?

                                          You did misunderstand what I said :-) I did not mean the method arguments, I meant the source object. In VB the source object itself can be passed by reference.

                                          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

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups