What variable type to declare

klaus

Expert
Licensed User
Longtime User
Some questions :

What variable type, from the perfomance point of view, should be used for:

1) For-Next loops ? For i=0 to 100
i as Number or undefined, Integer is not supported ?

2) array variable indexes Dim x(i,j) ?
i and j as Number, Integer or undefined ?

3) drawing, pixels Drawer.DrawRectangle2(pen.Value, x1, y1, w, h)
x1,y1, w, h Integer or Number ?

4) Why not having used the standard variable type names for the declarations ?
Double instead of Number ?
Int32 instead of Integer ?

Best regards.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
1,2,3) Basic4ppc internally does all the calculations with doubles. So an integer will be first cast to double and eventually back to integer. So double will be faster.
Note that this may change in the future.
I believe that in most cases the difference between integer to double will be insignificant.

4) Using Number is equivalent to using Double and the same is correct for Integer and Int32.
I think that from a developer point of view who is not familiar with all the .Net data types (and especially since double is the best choice in almost all cases in Basic4ppc) declaring a variable as Number is more clear than declaring it as a Double.
 
Top