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 43 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.
  • N Nemanja Trifunovic

    AspDotNetDev wrote:

    It is faster to read "{}" than "Then End If",

    Kind of. End If closes the block after If and that's it. To get what } does you need to be aware of the scope - sometimes even to scroll up a couple of pages. Sure, a good editor helps, but as far as a language goes I like End If better.

    utf8-cpp

    P Offline
    P Offline
    PIEBALDconsult
    wrote on last edited by
    #42

    See what happens when you remove all the newlines. Readable?

    1 Reply Last reply
    0
    • A AspDotNetDev

      Doesn't look fixed to me. Methinks you need to get the permalink from whatever message you are linking to.

      [WikiLeaks Cablegate Cables]

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #43

      My post "Here's something else VB can't do".

      A 1 Reply Last reply
      0
      • P PIEBALDconsult

        My post "Here's something else VB can't do".

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

        Ah, link.

        [WikiLeaks Cablegate Cables]

        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]

          M Offline
          M Offline
          Michael Kingsford Gray
          wrote on last edited by
          #45

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

          K 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]

            H Offline
            H Offline
            hairy_hats
            wrote on last edited by
            #46

            AspDotNetDev wrote:

            You're turn

            Am I? ;P

            R 3 Replies Last reply
            0
            • A AspDotNetDev

              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.

              [WikiLeaks Cablegate Cables]

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

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

              A K 2 Replies Last reply
              0
              • N Nish Nishant

                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

                R Offline
                R Offline
                Rob Grainger
                wrote on last edited by
                #48

                Nishant Sivakumar wrote:

                Oh sorry, it's so well known that I didn't think you'd need code to back it up

                maybe in your part of the world - I've been using C# and VB for years but never came across this. Why you'd want to do it in a well designed program is questionable, but maybe there is a good reason somewhere.

                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]

                  C Offline
                  C Offline
                  coding4ever
                  wrote on last edited by
                  #49

                  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 1 Reply Last reply
                  0
                  • H hairy_hats

                    AspDotNetDev wrote:

                    You're turn

                    Am I? ;P

                    R Offline
                    R Offline
                    raducu1
                    wrote on last edited by
                    #50

                    In VB.NET:

                    With longDescriptiveObjectName
                    .prop1 = ...
                    .prop2 = ...
                    .prop3 = ...
                    end with

                    In C#:

                    longDescriptiveObjectName.prop1 = ...
                    longDescriptiveObjectName.prop2 = ...
                    longDescriptiveObjectName.prop3 = ...

                    Which one is more verbose, then ?

                    1 Reply Last reply
                    0
                    • H hairy_hats

                      AspDotNetDev wrote:

                      You're turn

                      Am I? ;P

                      R Offline
                      R Offline
                      raducu1
                      wrote on last edited by
                      #51

                      Yes, you are VERY turn ! :((

                      1 Reply Last reply
                      0
                      • N Nish Nishant

                        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 Select

                        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

                        R Offline
                        R Offline
                        Rick Shaub
                        wrote on last edited by
                        #52

                        In C# you can use fall through cases for that in C#.

                        1 Reply Last reply
                        0
                        • H hairy_hats

                          AspDotNetDev wrote:

                          You're turn

                          Am I? ;P

                          R Offline
                          R Offline
                          raducu1
                          wrote on last edited by
                          #53

                          Again. if a=b { do something } What's unclear here ? However, the compiler stops me with the question - do you want to assign b to a ? No, I don't. Isn't it obvious what I want to do ? VB doesn't need this handholding. Also, why do I need to type if (a=b) { do something } and what do those fing paranthesis do there ? If I wanted to better delimit the clauses, for human eyes benefit only, I would do that, as in, say, if ((a=b) && (c=d)) { } Also... operators. I really don't care how awkwardly they were named in C, C++, etc, but really, people, baggage should NOT be carried forward && instead of AND ? || instead of OR ? != instead of <> ! instead of NOT ? No, really, what am I ? A compiler ? My hands won't fall off if I type (cond1) AND (cond2) instead of (cond1) && (cond2). There's one extra character and it's so much clearer ! Why do so many people love cryptic code ? It's not like the writer of that code will seem to be any smarter ! Also, the compiler stops and hits me with a brick saying that in the line variable1 = "abc" variable2 = 5; I have missed the ending ; on the first line. Well... if you compiler are so sure about my missing of that fing semicolon, why don't you put it there ? Warn me, color it bright red, make it blink, but put it there if you are so sure I've missed it. Help me a bit. I write in C#, and I really like it, don't get me wrong. But that doesn't make me not see these (and others) things.

                          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]

                            F Offline
                            F Offline
                            frattaro
                            wrote on last edited by
                            #54

                            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 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]

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