On May 1, 2007, at 4:47 PM, [EMAIL PROTECTED] wrote:

>> Let's say your average method is 50 NCSL, is it not a negligible  
>> thing
>> to move the DIMs to the top? You are in the scope of the method, so
>> how much closer do you really need to be?
>
> As close as they can be, since that helps them clarify the intent of
> the code.  At the top, they mean nothing but "I'm using an integer
> somewhere in this method for some ill-defined period of time."
> Declared properly, they mean "I'm using an integer right here, until
> the end of the block; this is where it matters, and beyond that you  
> can
> forget about it."

I won't weigh in on this debate since I have no position, but I have  
a question.

My experience is with variable declarations at the top so I haven't  
gotten used to declaring them later in code, but I can see some value  
in doing so. However, the one aspect that confuses me is how do you  
"undeclare" a variable? Can you? I mean, how else would the variable  
only be good for that block?

For instance, say I'm going to use a throw-away "i" variable as a  
loop counter somewhere in my code. It does make sense to declare it  
just before the loop. But how does my code know I'm done using it?  
Once I've declared it, isn't it still usable elsewhere in the  
subsequent code? And if that "i" is alive at any point after I've  
declared it, maybe I'll use it elsewhere... in which case if I  
refactor and move that "dim and loop" to a method, suddenly that  
later code breaks because it now uses an undeclared variable. How's  
that different from just declaring it at the top? Either way I've got  
a "loose" variable I'm only using on occasion throughout the code. I  
can see where dimming it later would be helpful the _first_ time it's  
used, but shouldn't it be declared every time it is used for such a  
technique to be useful? Or am I misunderstanding the scope of how a  
declaration works?



Marc Zeedar
Publisher, REALbasic Developer magazine
www.rbdeveloper.com


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>

Reply via email to