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. Visual Basic
  4. Variable Declaration

Variable Declaration

Scheduled Pinned Locked Moved Visual Basic
questioncomtools
4 Posts 2 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
    jcrussell
    wrote on last edited by
    #1

    I just read a post (http://www.codeproject.com/script/comments/forums.asp?msg=1325064&forumid=1640#xx1325064xx[^]) that talks about only declaring variables at the top of the function if you are writing in C What is the basis of this? I do all my declarations at the top of my functions so that they are easy to find structurally. /jason

    C 1 Reply Last reply
    0
    • J jcrussell

      I just read a post (http://www.codeproject.com/script/comments/forums.asp?msg=1325064&forumid=1640#xx1325064xx[^]) that talks about only declaring variables at the top of the function if you are writing in C What is the basis of this? I do all my declarations at the top of my functions so that they are easy to find structurally. /jason

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

      The reason you should do it in C, is because C requires it. The reason not to do it otherwise is because it makes your code harder to read, and harder to debug. You should read 'Code Complete' to get more insight into good code style, it's an excellent book. But as a starter - the code posted created a bunch of uninitialised variables, then proceeded to give them all values. How is that useful ? He could have done the same in half the lines, thus increasing readability, and making sure that no variables existed without being given the values you wanted them to start with. Christian Graus - Microsoft MVP - C++

      J 1 Reply Last reply
      0
      • C Christian Graus

        The reason you should do it in C, is because C requires it. The reason not to do it otherwise is because it makes your code harder to read, and harder to debug. You should read 'Code Complete' to get more insight into good code style, it's an excellent book. But as a starter - the code posted created a bunch of uninitialised variables, then proceeded to give them all values. How is that useful ? He could have done the same in half the lines, thus increasing readability, and making sure that no variables existed without being given the values you wanted them to start with. Christian Graus - Microsoft MVP - C++

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

        it wasn't my code ;) I tend to declare and initialise all my variables at the top of my procedure\functions, so that I know where they all are. It really isn't a big issue because I try and keep my procedures pretty small, but I like having them at the top. I can't justify it which is why I found your statement that it shouldn't be done that way interesting Thanks for the book recommendation. I will look into it /jason

        C 1 Reply Last reply
        0
        • J jcrussell

          it wasn't my code ;) I tend to declare and initialise all my variables at the top of my procedure\functions, so that I know where they all are. It really isn't a big issue because I try and keep my procedures pretty small, but I like having them at the top. I can't justify it which is why I found your statement that it shouldn't be done that way interesting Thanks for the book recommendation. I will look into it /jason

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

          Sorry, I worked that out later :-O Keeping your functions small is another recommendation from the book, actually. You'll probably find, as I did, that most things it recommends, you do, but it's worthwhile just to think about the reasons why. Christian Graus - Microsoft MVP - C++

          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