Yes I know but I like my locals XD.
I think with the "local" it just looks cleaner somehow.
But I also just realized Indigo, the IDE I'm using, colours the variables wrong if I declare them without "local".
Without it Indigo colours them as globals for whatever reason XD.
Another thing is I'm always delcaring variables with the datatype.
String for example I declare like that:
And I'm declaring all variables at the beginning of the function.
So if I look at the top of a function I can see all variables used in said function.
If you really want to get the best performance possible it's bad to have a function declare several variables that aren't even needed every time it'sc called.
In my current project I'm creating 10.000 objects in 19 ms or something like that.
So basically for every single variable in any of those functions I'm considering:
Do I really need this variable?
Am I able to achieve the goal with another method based on existing variables?
Or is it possible to tunnel the value directly?
For example if used
very often this function ...
FUNCTION vo_exist(vo AS DWORD)
IF vo = 0 THEN EXITFUNCTION vo_FALSE
IF vo > vobject_size THEN EXITFUNCTION vo_FALSE
IF vobject(vo) = 0 THEN EXITFUNCTION vo_FALSE
ENDFUNCTION vo_TRUE
... Is more performant than this:
FUNCTION vo_exist(vo AS DWORD)
LOCAL Exist AS BOOLEAN
IF vo > 0 AND vo <= vobject_size
IF vobject(vo) > 0
Exist = vo_TRUE
ENDIF
ENDIF
ENDFUNCTION Exist
The first version is faster simply because in some cases 1 equation is done while the second version always does at least 2 equations.
Also the second version is delcaring an unnecessary variable where I can give the values right back.
A nice side-effect is that IMO the first version is far easier to read and understand.
If you want to run this ~500.000 times in 19 ms ( not to mention the other code of course ) you have to think about every variable.
Well, or at least I'm doing this. XD