in reply to Improve my coding

Going to go against the popular vote on the variable declarations at the top. Old style rules in other languages put them at the top so as to make the question "Where are these from" easier. Easy to find and easy to change; burying them in conditionals stinks IMO.

Replies are listed 'Best First'.
Re^2: Improve my coding
by GrandFather (Saint) on Nov 25, 2009 at 20:17 UTC

    The compelling reason for putting variables in the smallest scope possible is that it greatly reduces the likely hood of "action at a distance" style errors that are the bane of using global variables.

    Another reason is that good coding style dictates that you declare the variable the first time it is used and initialize it at the same time. It's good coding style because it makes it clear where the variable is first used and how it gets its initial value.


    True laziness is hard work