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. General Programming
  3. Design and Architecture
  4. Detecting a right way to use variables in .Net

Detecting a right way to use variables in .Net

Scheduled Pinned Locked Moved Design and Architecture
databaseperformancecsharptoolsquestion
10 Posts 5 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.
  • J Offline
    J Offline
    JayKhatri
    wrote on last edited by
    #1

    Hi, I am using Dim str as string frequently in my windows application mostly to fill any dataset to query anything and more. basically how I use this is as follows: Dim dSetTemp As New DataSet Dim str As String str = "select trans_vchr.trans_vchr_id, trans_vchr.session_cfee_id, blah blah...." dSetTemp = clscmn.Fill_DS(str) --> fill_ds is a function created to increase the productivity. Here if I like I can easily do the same like this dSetTemp = clscmn.Fill_DS("select trans_vchr.trans_vchr_id, trans_vchr.session_cfee_id, blah blah....") Here my question is whether I use str variable or not, actually I use the variable as it make my debugging so easy I just copy the string and paste in sql to test the query. Here that gives me productivity while debugging but if it is at the cost of performance. I would compromise with debugging facility or If it is negligible, it can be left. Can you suggest what will be best for me. I like to save bytes to be loaded in memory and like to have best performance. Thanks in Advance. Jay Khatri

    L R G 3 Replies Last reply
    0
    • J JayKhatri

      Hi, I am using Dim str as string frequently in my windows application mostly to fill any dataset to query anything and more. basically how I use this is as follows: Dim dSetTemp As New DataSet Dim str As String str = "select trans_vchr.trans_vchr_id, trans_vchr.session_cfee_id, blah blah...." dSetTemp = clscmn.Fill_DS(str) --> fill_ds is a function created to increase the productivity. Here if I like I can easily do the same like this dSetTemp = clscmn.Fill_DS("select trans_vchr.trans_vchr_id, trans_vchr.session_cfee_id, blah blah....") Here my question is whether I use str variable or not, actually I use the variable as it make my debugging so easy I just copy the string and paste in sql to test the query. Here that gives me productivity while debugging but if it is at the cost of performance. I would compromise with debugging facility or If it is negligible, it can be left. Can you suggest what will be best for me. I like to save bytes to be loaded in memory and like to have best performance. Thanks in Advance. Jay Khatri

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      IMO the cost difference is very small and irrelevant; the debugging comfort is a perfect reason for using the string variable. :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      J 1 Reply Last reply
      0
      • L Luc Pattyn

        IMO the cost difference is very small and irrelevant; the debugging comfort is a perfect reason for using the string variable. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        J Offline
        J Offline
        JayKhatri
        wrote on last edited by
        #3

        thanks for such a quicky answer.

        1 Reply Last reply
        0
        • J JayKhatri

          Hi, I am using Dim str as string frequently in my windows application mostly to fill any dataset to query anything and more. basically how I use this is as follows: Dim dSetTemp As New DataSet Dim str As String str = "select trans_vchr.trans_vchr_id, trans_vchr.session_cfee_id, blah blah...." dSetTemp = clscmn.Fill_DS(str) --> fill_ds is a function created to increase the productivity. Here if I like I can easily do the same like this dSetTemp = clscmn.Fill_DS("select trans_vchr.trans_vchr_id, trans_vchr.session_cfee_id, blah blah....") Here my question is whether I use str variable or not, actually I use the variable as it make my debugging so easy I just copy the string and paste in sql to test the query. Here that gives me productivity while debugging but if it is at the cost of performance. I would compromise with debugging facility or If it is negligible, it can be left. Can you suggest what will be best for me. I like to save bytes to be loaded in memory and like to have best performance. Thanks in Advance. Jay Khatri

          R Offline
          R Offline
          Ray Cassick
          wrote on last edited by
          #4

          Yeah, I agree with Luc, this seems like such a small impact that the benefits of being able to 'see' the string in the debugger might outweigh the efficiency of the hard coded string... But if you ever have questions like this again you can also do a few things... 1) Code it both ways and open the executables up in reflector to see the IL. That sometimes shows you that no matter how you 'code' it, the compiler may just be optimizing it out for you. 2) Code it both ways and throw it in a huge loop then run it a few thousand times to get some performance numbers. See how it uses memory. See how the GC acts, etc...


          LinkedIn[^] | Blog[^] | Twitter[^]

          J 1 Reply Last reply
          0
          • R Ray Cassick

            Yeah, I agree with Luc, this seems like such a small impact that the benefits of being able to 'see' the string in the debugger might outweigh the efficiency of the hard coded string... But if you ever have questions like this again you can also do a few things... 1) Code it both ways and open the executables up in reflector to see the IL. That sometimes shows you that no matter how you 'code' it, the compiler may just be optimizing it out for you. 2) Code it both ways and throw it in a huge loop then run it a few thousand times to get some performance numbers. See how it uses memory. See how the GC acts, etc...


            LinkedIn[^] | Blog[^] | Twitter[^]

            J Offline
            J Offline
            JayKhatri
            wrote on last edited by
            #5

            nice one ray and impressive too. Thanks alot for your anticipation. I have more queries which arise time by time. Hope I will get this kind of reply then. Best Regards Jay Khatri

            D 1 Reply Last reply
            0
            • J JayKhatri

              nice one ray and impressive too. Thanks alot for your anticipation. I have more queries which arise time by time. Hope I will get this kind of reply then. Best Regards Jay Khatri

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              Ray is correct, but he left out one little detail. If you run the code compiled under Debug build, optimizations are turned off. This can make the code run a bit differently (and slower) in Debug then it would in Release. So if you want to test this, make sure you compile a Release build.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak

              J R 2 Replies Last reply
              0
              • D Dave Kreskowiak

                Ray is correct, but he left out one little detail. If you run the code compiled under Debug build, optimizations are turned off. This can make the code run a bit differently (and slower) in Debug then it would in Release. So if you want to test this, make sure you compile a Release build.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak

                J Offline
                J Offline
                JayKhatri
                wrote on last edited by
                #7

                Great!!! that make a big difference. Thanks for the addition. Jay Khatri

                1 Reply Last reply
                0
                • D Dave Kreskowiak

                  Ray is correct, but he left out one little detail. If you run the code compiled under Debug build, optimizations are turned off. This can make the code run a bit differently (and slower) in Debug then it would in Release. So if you want to test this, make sure you compile a Release build.

                  A guide to posting questions on CodeProject[^]
                  Dave Kreskowiak

                  R Offline
                  R Offline
                  Ray Cassick
                  wrote on last edited by
                  #8

                  Yes, I agree, and it can change the way the IL is constructed also. Thanks for bringing that up.


                  LinkedIn[^] | Blog[^] | Twitter[^]

                  D 1 Reply Last reply
                  0
                  • R Ray Cassick

                    Yes, I agree, and it can change the way the IL is constructed also. Thanks for bringing that up.


                    LinkedIn[^] | Blog[^] | Twitter[^]

                    D Offline
                    D Offline
                    Dave Kreskowiak
                    wrote on last edited by
                    #9

                    Not a problem. It's something that I was reminded of about a week ago. ;)

                    A guide to posting questions on CodeProject[^]
                    Dave Kreskowiak

                    1 Reply Last reply
                    0
                    • J JayKhatri

                      Hi, I am using Dim str as string frequently in my windows application mostly to fill any dataset to query anything and more. basically how I use this is as follows: Dim dSetTemp As New DataSet Dim str As String str = "select trans_vchr.trans_vchr_id, trans_vchr.session_cfee_id, blah blah...." dSetTemp = clscmn.Fill_DS(str) --> fill_ds is a function created to increase the productivity. Here if I like I can easily do the same like this dSetTemp = clscmn.Fill_DS("select trans_vchr.trans_vchr_id, trans_vchr.session_cfee_id, blah blah....") Here my question is whether I use str variable or not, actually I use the variable as it make my debugging so easy I just copy the string and paste in sql to test the query. Here that gives me productivity while debugging but if it is at the cost of performance. I would compromise with debugging facility or If it is negligible, it can be left. Can you suggest what will be best for me. I like to save bytes to be loaded in memory and like to have best performance. Thanks in Advance. Jay Khatri

                      G Offline
                      G Offline
                      GParkings
                      wrote on last edited by
                      #10

                      I generally go with whatever is more readable (if its a long string and i use it inline then it pushes the rest of the method off the screen) and easiest to debug. One thing to consider though, if you have a string that is potentially being declared inline then that string is a constant, why not make it a constant? As part of my 'final tidyup' i generally go through my code looking for " characters and numbers, if i find any i ask myself why they aren't constant, 9 times out of 10 they should be :D

                      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