Local Variables Declaration


Link to this posting

Postby Ursego » 19 Feb 2013, 22:13

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:

Fragment 1:

Code: Select all
long ll_row
if <condition> then
      ll_row = …
end if

Fragment 2:

Code: Select all
if <condition> then
      long ll_row
      ll_row = …
end if
User avatar
Ursego
Site Admin
 
Posts: 113
Joined: 19 Feb 2013, 20:33

IF you want to ((lose weight) OR (have unbelievable (brain function AND mental clarity))) THEN click:




cron
free counters

eXTReMe Tracker