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. No one can say languages are the same to me ever again!

No one can say languages are the same to me ever again!

Scheduled Pinned Locked Moved The Lounge
csharpdatabasedotnetwpf
40 Posts 15 Posters 0 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.
  • L Offline
    L Offline
    LongRange Shooter
    wrote on last edited by
    #1

    I just finished a grueling 15 system code review. Sheesh. But interesting of all is that there was quite a mix of VB.NET as well as C#.NET. There were two things that caught my eye in these reviews right away: 1) when the developer got a row from the database but did no casting whatsoever (to populate a string field) VB.NET compiled the code without complaint. It then resulted in IL that called GetValueFromObject that then was passed into StrObj.StringFromObject. 2) when a developer accessed a method inside a dll that was referenced but no using statement given, VB.NET compiled the code without complaint. The IL it puked out was LateBinding creation of the object and LateBindingCall into the method. ...and the reason for all of this review was to find out why the applications are running so slow. In looking at the IL from the C# code, not once did I have a cast from object or a late binding call in any of the code. Simply because C# would not allow these common faux paxs to occur. So no one could ever tell me that VB.NET generates exactly the same IL as C# does. Now----> before anyone begins the counters ---> a well written VB.NET program (I did encounter 1) will generate the same code in C# as in VB.NET. As long as the developer is not lazy, checks the object types he/she is working with, and makes certain to always add a Imports statements every time a reference is added. Also -- some of the C# code was not all that pretty and there was an extensive amount of string concatenation using "a" + "b" + ... as well as excessive object casting and creation. But that just shows a bad developer can write bad code in either language. But I now understand what one Microsoft engineer (off the record) meant when he stated that 'even a good developer can easily write bad code in VB.NET'. -- modified at 13:48 Wednesday 15th March, 2006

    C D R N S 8 Replies Last reply
    0
    • L LongRange Shooter

      I just finished a grueling 15 system code review. Sheesh. But interesting of all is that there was quite a mix of VB.NET as well as C#.NET. There were two things that caught my eye in these reviews right away: 1) when the developer got a row from the database but did no casting whatsoever (to populate a string field) VB.NET compiled the code without complaint. It then resulted in IL that called GetValueFromObject that then was passed into StrObj.StringFromObject. 2) when a developer accessed a method inside a dll that was referenced but no using statement given, VB.NET compiled the code without complaint. The IL it puked out was LateBinding creation of the object and LateBindingCall into the method. ...and the reason for all of this review was to find out why the applications are running so slow. In looking at the IL from the C# code, not once did I have a cast from object or a late binding call in any of the code. Simply because C# would not allow these common faux paxs to occur. So no one could ever tell me that VB.NET generates exactly the same IL as C# does. Now----> before anyone begins the counters ---> a well written VB.NET program (I did encounter 1) will generate the same code in C# as in VB.NET. As long as the developer is not lazy, checks the object types he/she is working with, and makes certain to always add a Imports statements every time a reference is added. Also -- some of the C# code was not all that pretty and there was an extensive amount of string concatenation using "a" + "b" + ... as well as excessive object casting and creation. But that just shows a bad developer can write bad code in either language. But I now understand what one Microsoft engineer (off the record) meant when he stated that 'even a good developer can easily write bad code in VB.NET'. -- modified at 13:48 Wednesday 15th March, 2006

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Yes, VB.NET is weakly typed. This is one of many ways that VB.NET allows you to write bad code, in the interest of helping people write code at all :-) As your off the record source said, this means you need to know the language REALLY well to write good code with it. Christian Graus - Microsoft MVP - C++

      1 Reply Last reply
      0
      • L LongRange Shooter

        I just finished a grueling 15 system code review. Sheesh. But interesting of all is that there was quite a mix of VB.NET as well as C#.NET. There were two things that caught my eye in these reviews right away: 1) when the developer got a row from the database but did no casting whatsoever (to populate a string field) VB.NET compiled the code without complaint. It then resulted in IL that called GetValueFromObject that then was passed into StrObj.StringFromObject. 2) when a developer accessed a method inside a dll that was referenced but no using statement given, VB.NET compiled the code without complaint. The IL it puked out was LateBinding creation of the object and LateBindingCall into the method. ...and the reason for all of this review was to find out why the applications are running so slow. In looking at the IL from the C# code, not once did I have a cast from object or a late binding call in any of the code. Simply because C# would not allow these common faux paxs to occur. So no one could ever tell me that VB.NET generates exactly the same IL as C# does. Now----> before anyone begins the counters ---> a well written VB.NET program (I did encounter 1) will generate the same code in C# as in VB.NET. As long as the developer is not lazy, checks the object types he/she is working with, and makes certain to always add a Imports statements every time a reference is added. Also -- some of the C# code was not all that pretty and there was an extensive amount of string concatenation using "a" + "b" + ... as well as excessive object casting and creation. But that just shows a bad developer can write bad code in either language. But I now understand what one Microsoft engineer (off the record) meant when he stated that 'even a good developer can easily write bad code in VB.NET'. -- modified at 13:48 Wednesday 15th March, 2006

        D Offline
        D Offline
        Duncan Edwards Jones
        wrote on last edited by
        #3

        Option Strict '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

        L 1 Reply Last reply
        0
        • L LongRange Shooter

          I just finished a grueling 15 system code review. Sheesh. But interesting of all is that there was quite a mix of VB.NET as well as C#.NET. There were two things that caught my eye in these reviews right away: 1) when the developer got a row from the database but did no casting whatsoever (to populate a string field) VB.NET compiled the code without complaint. It then resulted in IL that called GetValueFromObject that then was passed into StrObj.StringFromObject. 2) when a developer accessed a method inside a dll that was referenced but no using statement given, VB.NET compiled the code without complaint. The IL it puked out was LateBinding creation of the object and LateBindingCall into the method. ...and the reason for all of this review was to find out why the applications are running so slow. In looking at the IL from the C# code, not once did I have a cast from object or a late binding call in any of the code. Simply because C# would not allow these common faux paxs to occur. So no one could ever tell me that VB.NET generates exactly the same IL as C# does. Now----> before anyone begins the counters ---> a well written VB.NET program (I did encounter 1) will generate the same code in C# as in VB.NET. As long as the developer is not lazy, checks the object types he/she is working with, and makes certain to always add a Imports statements every time a reference is added. Also -- some of the C# code was not all that pretty and there was an extensive amount of string concatenation using "a" + "b" + ... as well as excessive object casting and creation. But that just shows a bad developer can write bad code in either language. But I now understand what one Microsoft engineer (off the record) meant when he stated that 'even a good developer can easily write bad code in VB.NET'. -- modified at 13:48 Wednesday 15th March, 2006

          R Offline
          R Offline
          Rama Krishna Vavilala
          wrote on last edited by
          #4

          theRealCondor wrote:

          find out why the applications are running so slow

          Does the application runs slowly because of this late binding only? Is that the major bottleneck?


          My Blog

          L 1 Reply Last reply
          0
          • R Rama Krishna Vavilala

            theRealCondor wrote:

            find out why the applications are running so slow

            Does the application runs slowly because of this late binding only? Is that the major bottleneck?


            My Blog

            L Offline
            L Offline
            LongRange Shooter
            wrote on last edited by
            #5

            Nope, not just late binding, but: late binding creation late binding calls deeply nested casting from object (a maximum of 14 casts in one line of code) extensive amounts of string concatenation that really stressed GC postbacks on datagrids requiring ViewState active ..and the list goes on.

            1 Reply Last reply
            0
            • L LongRange Shooter

              I just finished a grueling 15 system code review. Sheesh. But interesting of all is that there was quite a mix of VB.NET as well as C#.NET. There were two things that caught my eye in these reviews right away: 1) when the developer got a row from the database but did no casting whatsoever (to populate a string field) VB.NET compiled the code without complaint. It then resulted in IL that called GetValueFromObject that then was passed into StrObj.StringFromObject. 2) when a developer accessed a method inside a dll that was referenced but no using statement given, VB.NET compiled the code without complaint. The IL it puked out was LateBinding creation of the object and LateBindingCall into the method. ...and the reason for all of this review was to find out why the applications are running so slow. In looking at the IL from the C# code, not once did I have a cast from object or a late binding call in any of the code. Simply because C# would not allow these common faux paxs to occur. So no one could ever tell me that VB.NET generates exactly the same IL as C# does. Now----> before anyone begins the counters ---> a well written VB.NET program (I did encounter 1) will generate the same code in C# as in VB.NET. As long as the developer is not lazy, checks the object types he/she is working with, and makes certain to always add a Imports statements every time a reference is added. Also -- some of the C# code was not all that pretty and there was an extensive amount of string concatenation using "a" + "b" + ... as well as excessive object casting and creation. But that just shows a bad developer can write bad code in either language. But I now understand what one Microsoft engineer (off the record) meant when he stated that 'even a good developer can easily write bad code in VB.NET'. -- modified at 13:48 Wednesday 15th March, 2006

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

              theRealCondor wrote:

              The IL it puked out was LateBinding creation of the object and LateBindingCall into the method.

              You mean it used Reflection? Regards, Nish


              Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
              The Ultimate Grid - The #1 MFC grid out there!

              L D 2 Replies Last reply
              0
              • D Duncan Edwards Jones

                Option Strict '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd

                L Offline
                L Offline
                LongRange Shooter
                wrote on last edited by
                #7

                ...yes, Option Strict does a nice job. But the developer has to know it is there and then he/she has to go in and set it with each new solution. Most of these developers were either VB6 developers or COBOL coders sent in to learn a new language. So few if any knew this option existed and did not have the inquisitiveness to seek it out. And since it is off by default (a mistake on the VB teams side IMHO) it usually is overlooked until it is too late. And when you do finally turn it on, then VB has this nice way of spitting out a short list of errors and reporting: Maximum number of errors reached. At that point the error list stops as does any further compilation.

                K 1 Reply Last reply
                0
                • L LongRange Shooter

                  I just finished a grueling 15 system code review. Sheesh. But interesting of all is that there was quite a mix of VB.NET as well as C#.NET. There were two things that caught my eye in these reviews right away: 1) when the developer got a row from the database but did no casting whatsoever (to populate a string field) VB.NET compiled the code without complaint. It then resulted in IL that called GetValueFromObject that then was passed into StrObj.StringFromObject. 2) when a developer accessed a method inside a dll that was referenced but no using statement given, VB.NET compiled the code without complaint. The IL it puked out was LateBinding creation of the object and LateBindingCall into the method. ...and the reason for all of this review was to find out why the applications are running so slow. In looking at the IL from the C# code, not once did I have a cast from object or a late binding call in any of the code. Simply because C# would not allow these common faux paxs to occur. So no one could ever tell me that VB.NET generates exactly the same IL as C# does. Now----> before anyone begins the counters ---> a well written VB.NET program (I did encounter 1) will generate the same code in C# as in VB.NET. As long as the developer is not lazy, checks the object types he/she is working with, and makes certain to always add a Imports statements every time a reference is added. Also -- some of the C# code was not all that pretty and there was an extensive amount of string concatenation using "a" + "b" + ... as well as excessive object casting and creation. But that just shows a bad developer can write bad code in either language. But I now understand what one Microsoft engineer (off the record) meant when he stated that 'even a good developer can easily write bad code in VB.NET'. -- modified at 13:48 Wednesday 15th March, 2006

                  S Offline
                  S Offline
                  Shog9 0
                  wrote on last edited by
                  #8

                  Heh. A while back, we ended up using two different wrappers for MSXML in our software, one generated by the VC6 wizard, the other generated at compile-time via the #import extension. Fundamental difference? The VC6-generated wrapper did everything through IDispatch. Guess which one performed significantly better when calling setAttribute() in a tight loop... ;) Moral of the story? If you don't know what your program is really doing, you're gonna have a hard time making it do what it needs to do faster.

                  ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

                  L 1 Reply Last reply
                  0
                  • N Nish Nishant

                    theRealCondor wrote:

                    The IL it puked out was LateBinding creation of the object and LateBindingCall into the method.

                    You mean it used Reflection? Regards, Nish


                    Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                    The Ultimate Grid - The #1 MFC grid out there!

                    L Offline
                    L Offline
                    LongRange Shooter
                    wrote on last edited by
                    #9

                    Well....I did not expand the logic that is inside Microsoft.VisualBasic.dll ...but it actually creates a call to LateBind(object name) and LatBindingCall(latebound object, object method name) It did not directly use Reflection. In fact within several of the functions like GetStringFromObject the Microsoft.VisualBasic.dll logic does not do a straightforward obj.ToString() call. Instead it does about a 15 statement switch statement based on the objects type. -- modified at 14:01 Wednesday 15th March, 2006

                    1 Reply Last reply
                    0
                    • N Nish Nishant

                      theRealCondor wrote:

                      The IL it puked out was LateBinding creation of the object and LateBindingCall into the method.

                      You mean it used Reflection? Regards, Nish


                      Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                      The Ultimate Grid - The #1 MFC grid out there!

                      D Offline
                      D Offline
                      Daniel Grunwald
                      wrote on last edited by
                      #10

                      Nishant Sivakumar wrote:

                      ?

                      Yes, if you forget to specify the type of a variable in VB, every member access on it will use Reflection.

                      1 Reply Last reply
                      0
                      • S Shog9 0

                        Heh. A while back, we ended up using two different wrappers for MSXML in our software, one generated by the VC6 wizard, the other generated at compile-time via the #import extension. Fundamental difference? The VC6-generated wrapper did everything through IDispatch. Guess which one performed significantly better when calling setAttribute() in a tight loop... ;) Moral of the story? If you don't know what your program is really doing, you're gonna have a hard time making it do what it needs to do faster.

                        ---- Scripts i've known... CPhog 0.9.9 - make CP better. Forum Bookmark 0.2.5 - bookmark forum posts on Pensieve Print forum 0.1.1 - printer-friendly forums

                        L Offline
                        L Offline
                        LongRange Shooter
                        wrote on last edited by
                        #11

                        Yup, in total agreement here. That is why I chose to evaluate all programs by using Reflector against the IL instead of reviewing the developers' straight source. (though I reviewed that as well) I wanted to make sure I reviewed all systems based upon what is being done under the covers rather than what was visually happening.

                        1 Reply Last reply
                        0
                        • L LongRange Shooter

                          I just finished a grueling 15 system code review. Sheesh. But interesting of all is that there was quite a mix of VB.NET as well as C#.NET. There were two things that caught my eye in these reviews right away: 1) when the developer got a row from the database but did no casting whatsoever (to populate a string field) VB.NET compiled the code without complaint. It then resulted in IL that called GetValueFromObject that then was passed into StrObj.StringFromObject. 2) when a developer accessed a method inside a dll that was referenced but no using statement given, VB.NET compiled the code without complaint. The IL it puked out was LateBinding creation of the object and LateBindingCall into the method. ...and the reason for all of this review was to find out why the applications are running so slow. In looking at the IL from the C# code, not once did I have a cast from object or a late binding call in any of the code. Simply because C# would not allow these common faux paxs to occur. So no one could ever tell me that VB.NET generates exactly the same IL as C# does. Now----> before anyone begins the counters ---> a well written VB.NET program (I did encounter 1) will generate the same code in C# as in VB.NET. As long as the developer is not lazy, checks the object types he/she is working with, and makes certain to always add a Imports statements every time a reference is added. Also -- some of the C# code was not all that pretty and there was an extensive amount of string concatenation using "a" + "b" + ... as well as excessive object casting and creation. But that just shows a bad developer can write bad code in either language. But I now understand what one Microsoft engineer (off the record) meant when he stated that 'even a good developer can easily write bad code in VB.NET'. -- modified at 13:48 Wednesday 15th March, 2006

                          T Offline
                          T Offline
                          ToddHileHoffer
                          wrote on last edited by
                          #12

                          Turn option strict on. If compile fails then code review = failed. If you turn option strict on then vb.net is more strict then C#. So your post is pointless. "People who never make mistakes, never do anything." My Blog -- modified at 14:13 Wednesday 15th March, 2006

                          C 1 Reply Last reply
                          0
                          • L LongRange Shooter

                            I just finished a grueling 15 system code review. Sheesh. But interesting of all is that there was quite a mix of VB.NET as well as C#.NET. There were two things that caught my eye in these reviews right away: 1) when the developer got a row from the database but did no casting whatsoever (to populate a string field) VB.NET compiled the code without complaint. It then resulted in IL that called GetValueFromObject that then was passed into StrObj.StringFromObject. 2) when a developer accessed a method inside a dll that was referenced but no using statement given, VB.NET compiled the code without complaint. The IL it puked out was LateBinding creation of the object and LateBindingCall into the method. ...and the reason for all of this review was to find out why the applications are running so slow. In looking at the IL from the C# code, not once did I have a cast from object or a late binding call in any of the code. Simply because C# would not allow these common faux paxs to occur. So no one could ever tell me that VB.NET generates exactly the same IL as C# does. Now----> before anyone begins the counters ---> a well written VB.NET program (I did encounter 1) will generate the same code in C# as in VB.NET. As long as the developer is not lazy, checks the object types he/she is working with, and makes certain to always add a Imports statements every time a reference is added. Also -- some of the C# code was not all that pretty and there was an extensive amount of string concatenation using "a" + "b" + ... as well as excessive object casting and creation. But that just shows a bad developer can write bad code in either language. But I now understand what one Microsoft engineer (off the record) meant when he stated that 'even a good developer can easily write bad code in VB.NET'. -- modified at 13:48 Wednesday 15th March, 2006

                            A Offline
                            A Offline
                            Alvaro Mendez
                            wrote on last edited by
                            #13

                            theRealCondor wrote:

                            there was an extensive amount of string concatenation using "a" + "b"

                            There's nothing wrong with that. This code: string s = "a" + "b"; gets compiled into: string s = "ab"; and, string s = "a" + someString + "c"; gets compiled into: string s = string.Concat("a", someString, "c"); Alvaro


                            ... since we've descended to name calling, I'm thinking you're about twenty pounds of troll droppings in a ten pound bag. - Vincent Reynolds

                            L J 2 Replies Last reply
                            0
                            • T ToddHileHoffer

                              Turn option strict on. If compile fails then code review = failed. If you turn option strict on then vb.net is more strict then C#. So your post is pointless. "People who never make mistakes, never do anything." My Blog -- modified at 14:13 Wednesday 15th March, 2006

                              C Offline
                              C Offline
                              Christian Graus
                              wrote on last edited by
                              #14

                              ToddHileHoffer wrote:

                              So your post is pointless.

                              No - 'there is an option that is off by default that people who have no idea what they are doing should know to turn on' is not a viable position, IMO. Christian Graus - Microsoft MVP - C++

                              N T 2 Replies Last reply
                              0
                              • C Christian Graus

                                ToddHileHoffer wrote:

                                So your post is pointless.

                                No - 'there is an option that is off by default that people who have no idea what they are doing should know to turn on' is not a viable position, IMO. Christian Graus - Microsoft MVP - C++

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

                                Christian Graus wrote:

                                No - 'there is an option that is off by default that people who have no idea what they are doing should know to turn on' is not a viable position, IMO.

                                The very fact that it's off by default is a pointer to the intended target audience for that compiler. Regards, Nish


                                Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                                The Ultimate Grid - The #1 MFC grid out there!

                                C 1 Reply Last reply
                                0
                                • A Alvaro Mendez

                                  theRealCondor wrote:

                                  there was an extensive amount of string concatenation using "a" + "b"

                                  There's nothing wrong with that. This code: string s = "a" + "b"; gets compiled into: string s = "ab"; and, string s = "a" + someString + "c"; gets compiled into: string s = string.Concat("a", someString, "c"); Alvaro


                                  ... since we've descended to name calling, I'm thinking you're about twenty pounds of troll droppings in a ten pound bag. - Vincent Reynolds

                                  L Offline
                                  L Offline
                                  LongRange Shooter
                                  wrote on last edited by
                                  #16

                                  You should read some of the articles written by Microsoft and also use Reflector to see what things get compiled into. a+b+c gets compiled into exactly that, a+b+c. execution then creates a string object that represents a, creates a new object that represents a+b, creates a new object that represents a+b+c then assigns that instance to the value variable. String.Concat() is different and performs the above in a slightly more efficient fashion, but a+b+c never gets compiled into a String.Concat unless you explicitely code it that way. And you still end up with some additional objects. Now you put that into a loop that performs a+b+c 75 times and you have somewhere in the neighborhood of 250 objects flooding the gc heaps. And, I believe, that each of these objects must be Finalized() which adds further overhead to the GC operation. On the otherhand, if you perform that loop with StringBuilder and cast it to a string, then you create only 2 objects on the heap. There are 10 kinds of people in the world.
                                  Those that read binary...
                                  ...and those who don't.

                                  A D 2 Replies Last reply
                                  0
                                  • N Nish Nishant

                                    Christian Graus wrote:

                                    No - 'there is an option that is off by default that people who have no idea what they are doing should know to turn on' is not a viable position, IMO.

                                    The very fact that it's off by default is a pointer to the intended target audience for that compiler. Regards, Nish


                                    Nish’s thoughts on MFC, C++/CLI and .NET (my blog)
                                    The Ultimate Grid - The #1 MFC grid out there!

                                    C Offline
                                    C Offline
                                    Christian Graus
                                    wrote on last edited by
                                    #17

                                    Nishant Sivakumar wrote:

                                    The very fact that it's off by default is a pointer to the intended target audience for that compiler.

                                    Now Nish, you know there are no pointers in VB... :P Christian Graus - Microsoft MVP - C++

                                    L J C 3 Replies Last reply
                                    0
                                    • C Christian Graus

                                      Nishant Sivakumar wrote:

                                      The very fact that it's off by default is a pointer to the intended target audience for that compiler.

                                      Now Nish, you know there are no pointers in VB... :P Christian Graus - Microsoft MVP - C++

                                      L Offline
                                      L Offline
                                      LongRange Shooter
                                      wrote on last edited by
                                      #18

                                      LOL :laugh: There are 10 kinds of people in the world.
                                      Those that read binary...
                                      ...and those who don't.

                                      1 Reply Last reply
                                      0
                                      • A Alvaro Mendez

                                        theRealCondor wrote:

                                        there was an extensive amount of string concatenation using "a" + "b"

                                        There's nothing wrong with that. This code: string s = "a" + "b"; gets compiled into: string s = "ab"; and, string s = "a" + someString + "c"; gets compiled into: string s = string.Concat("a", someString, "c"); Alvaro


                                        ... since we've descended to name calling, I'm thinking you're about twenty pounds of troll droppings in a ten pound bag. - Vincent Reynolds

                                        J Offline
                                        J Offline
                                        Jim Crafton
                                        wrote on last edited by
                                        #19

                                        I think you missed something - you're referring to compile time optimizations with string literals, whereas the OP is saying that all of the string concatenation is happening at runtime, all dynamically generated, so I doubt it would be able to do this, or at least not as effectively. ¡El diablo está en mis pantalones! ¡Mire, mire! Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)! SELECT * FROM User WHERE Clue > 0 0 rows returned Save an Orange - Use the VCF!

                                        1 Reply Last reply
                                        0
                                        • L LongRange Shooter

                                          You should read some of the articles written by Microsoft and also use Reflector to see what things get compiled into. a+b+c gets compiled into exactly that, a+b+c. execution then creates a string object that represents a, creates a new object that represents a+b, creates a new object that represents a+b+c then assigns that instance to the value variable. String.Concat() is different and performs the above in a slightly more efficient fashion, but a+b+c never gets compiled into a String.Concat unless you explicitely code it that way. And you still end up with some additional objects. Now you put that into a loop that performs a+b+c 75 times and you have somewhere in the neighborhood of 250 objects flooding the gc heaps. And, I believe, that each of these objects must be Finalized() which adds further overhead to the GC operation. On the otherhand, if you perform that loop with StringBuilder and cast it to a string, then you create only 2 objects on the heap. There are 10 kinds of people in the world.
                                          Those that read binary...
                                          ...and those who don't.

                                          A Offline
                                          A Offline
                                          Alvaro Mendez
                                          wrote on last edited by
                                          #20

                                          theRealCondor wrote:

                                          You should read some of the articles written by Microsoft and also use Reflector to see what things get compiled into.

                                          :wtf: You think I'm pulling what I said out of my ass? Evidently you're the one who needs to use Reflector. C#:

                                          public void TESTING_STRINGS()
                                          {
                                          string s1 = "a" + "b";
                                          string s2 = "a" + s1 + "c";
                                          }

                                          IL:

                                          .method public hidebysig instance void TESTING_STRINGS() cil managed
                                          {
                                          .maxstack 3
                                          .locals init (
                                          string text1,
                                          string text2)
                                          L_0000: ldstr "ab"
                                          L_0005: stloc.0
                                          L_0006: ldstr "a"
                                          L_000b: ldloc.0
                                          L_000c: ldstr "c"
                                          L_0011: call string string::Concat(string, string, string)
                                          L_0016: stloc.1
                                          L_0017: ret
                                          }

                                          Alvaro


                                          ... since we've descended to name calling, I'm thinking you're about twenty pounds of troll droppings in a ten pound bag. - Vincent Reynolds

                                          L 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