QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: bobtheunplayer on February 05, 2019, 10:05:45 am
-
Is it better to
Or
-
I think it is a preference thing but declaring variables with DIM before using with Option Explicit can save tons of time cost by typo.
OTOH, Strings with $ are self documenting, I like $ for strings (Explicit free) but it is an extra character to type. And in usually smaller SUBs and Functions there is not an overwhelming amount of variables to track.
Declaring in parameters list the type with AS might be handy with reusable routines.
Be careful with subs that will try to pass back arguments by ref. ie if you change a value of argument in a sub that change might effect main program with that variable.
-
Of course, there's always my way!...
-
Hey boy, you forget that my way is better !
:-)
It's better to share only what it is useful and/or necessary!
:-)
-
Hey boy, you forget that my way is better !
:-)
It's better to share only what it is useful and/or necessary!
:-)
TempodiBasic, do you mean this? (Because the line Bar = "baz" is an error in the sub.)
-
Yes you're right
but when I am hangry this is the result!
:-)))
So I have had or AS STRING in the SUB
or DEFSTR A-T
Bar = "" in the main!
:-)))
-
Is it better to
Or
My personal preference here tends to lie towards: “DIM memorable variables, don’t worry with temp variables”
SUB Foo
DIM Velocity AS _FLOAT
DIM Gravity AS _FLOAT
DIM RacecarDriver AS STRING
c$ = “PRESS <ANY KEY> TO CONTINUE.”
e$ = “<ESC> TO END.”
..... more stuff
END SUB
Important variables name and help document themselves. Temp/Trash variables are suffixed, quickly used, and forgotten.
It’s generally the basic guideline I follow, myself.
-
Thanks for all the feedback guys. I think what I meant was more about what is the cost of static vs dynamic typing. Which is more efficient? Or, does it not even matter?
Thanks,
Bob