On Apr 06, 2007, at 13:26 UTC, Eric Pousse wrote:

> Is there a big advantage to put "Dim declares" into the code instead 
> of before the code?
> I ask this because I have old codes and only if advantage is big, I  
> will change place of "Dim declares".
> Which kind of advantages can there be?

1. It makes the code easier to refactor when a variable is declared
right where it is needed.  This way, if you decide to Extract Method,
you can just grab that whole block of code (including its local
variable declarations) and cut it out to paste elsewhere.  If the
variable declarations are at the top, you have a lot more work to do
finding out which ones you need.

2. When you declare a variable inside a code block (e.g. inside a For
loop or If block), then it goes away as soon as the block exits.  This
has the compile-time advantage that you won't inadvertently use a
variable whose value no longer makes sense (e.g. by mistyping some
other similarly-named variable).  And it has the run-time advantage
that the object's storage is deallocated right away, freeing up memory
that may be needed by code later in the method, and also releasing
resources like files that later code may want to use.

I wouldn't bother to go through and change all your existing code if I
were you, but I would recommend getting in the habit of declaring
variables right where they're used for any future code you write.

Best,
- Joe

--
Joe Strout -- [EMAIL PROTECTED]
Verified Express, LLC     "Making the Internet a Better Place"
http://www.verex.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