Declare local vars in the beginning (on the top) of the method, before the first executable line.

That will:

1. Make it easier to detect all the variables, used in the method, and to follow them. Most programmers immediately look in the beginning of a program for variables declaration.

2. Keep as little stuff as possible in executable code fragments, where programmers should concentrate on business logic.

In PowerBuilder (in contrast to Java), the local variable declaration is not an executable command. The memory is allocated on the stack when the function is being called - together with the parameters.

So, declaring a variable inside an if block does not improve performance – memory will be allocated even when the program flow doesn’t go into the if. The following two fragments produce a same binary code: