[futurebasic] Re: [FB] Back to basics - A dim question

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : September 2001 : Group Archive : Group : All Groups

From: Chris Stasny <staz@...>
Date: Thu, 27 Sep 2001 08:23:57 -0500
>Someone once said "Better to be thought a fool than to speak and remove all
>doubt".
>But, sod it!... here goes:
>
>
>Can anyone explain the advantages of DIMing local vars?
>Are there any speed gains? Could it prevent crashes?
>
>Also, assuming that the following give identical results, are the different
>ways of DIMing 'myVar' purely for back compatibility?
>DIM myVar
>DIM myVar%
>DIM myVar AS INTEGER
>
>Also2, is there any advantage/disadvantage in DIMing a var which appears in
>the parameter list of a local fn?


Advantage 1: When you turn on Dimmed vars only, the compiler catches 
many of your mistakes. Here's one example:

x = SYSTEM(aplVol)

It looks normal and it will compile unless you use only dimmed vars. 
This mistake is the missing underscore. But that's a big mistake. In 
this example aplVol is a random variable where _aplVol is a defined 
constant. Other mistakes (misspelling variable names and failing to 
change var names when copying and pasting) are also caught.

Advantage 2: Sometimes (like maybe 1/2 of 1% of the time) you end up 
tweaking a few lines that get executed millions of times. Forcing 
often used vars into register will speed things up (because register 
access is more that twice as fast as memory access). FB puts 
variables in registers as soon as they are encountered so items 
dimmed early are likely to fall into registers. Heavy use of vars (in 
a local fn) will mean that the registers are eventually filled and 
remaing vars spill over into slower RAM. So dim your often used vars 
first and insure that they go into registers.

Advantage 3: A program is much more readable if you use the following format:

LOCAL
DIM xyz AS long     // this is a comment about xyz
DIM a$              // this is about a$
LOCAL FN Bubba(h AS HANDLE)
etc.

Advantage 4: No more ugly yellow toenail fungus.
-- 


Best,

-STAZ  ~)~

800.348.2623 Orders  http://www.stazsoftware.com
228.255.7086 FAX     mailto:staz@...