Recently there was a blog post on Xojo’s blog from Wayne Golding about how 2019r2 and newer accept VAR as a keyword to declare a variable. And they still accept the older DIM.
There are some issues with VAR IF you ever have to move your code to an older version. I know a lot of developers of commercial software that have to do this so they can continue to support their clients running older versions of various operating systems.
These people have stayed with the older DIM so they can easily move their code simply.
Adding VAR as a keyword has some issues though. While I agree that VAR is an awful parameter or variable name there is code that has used it that now suddenly won’t compile.
One thing I asked for was rather than adding a new keyword, with all the issues that can bring, that we just NOT have to put a DIM or VAR. Then we could write
dim foo as integer
var bar as double
d as date
In a compiler there is usually a “grammar” – a set of rules for what the compiler considers valid code and what it doesn’t. And somewhere in Xojo’s grammar there is a rule that says a variable declaration has to look a specific way. (This is a wild assed guess on my part not actual code since I do not have the code for this)
variableDecl :
DIM listofVariablesAndTypes
| VAR listofVariablesAndTypes
and listofVariablesAndTypes is additional rules for how to declare one or more variables with default values in a single line. Making this grammar rule
variableDecl :
DIM listofVariablesAndTypes
| VAR listofVariablesAndTypes
| listofVariablesAndTypes
(or something like this) would make it so DIM and VAR are not required.
I’d find it handy.
How about you ?
Dimension seems like a verb, so “dim i as integer” makes sense.
Variable seems like a noun, so “var i IS integer” sounds better.
Neither one is really necessary.
Syntactically there’s no other place that you could mistake a variable decalaration for anything else
As a move to modernize Xojo and the language its a teeny tiny step and they could have made it possible to use either var or dim or neither one.
Neither one would have made me happy but … it is what it is