Is it better to declare variables at the start of a proc, or closer to where 
needed?

Thinking about loops
    
    
    proc testProc() =
      for i in 0..100:
        var j = ""
        j = $i
    
    
    Run

There is overhead to create and destroy a variable 100 times. Yet, program best 
practices are to keep variable declarations near the location of use, as 
practical. Usually I declare at the top, but sometimes declare inside a loop. 
While cleaning up old code I came across this and realized I had no rationale 
reason for doing it one way or another. 

Reply via email to