Many long-time contributors to the forum seem to prefer using Dim rather than Var in the example code they provide. I assume that various AI chatbots are trained on this material. I wonder whether it would make it easier for them and ultimately the rest of us to distinguish API 2 code from older code if people used Var consistently going forward.
Guilty.
20 years of habit, and still avoiding API2, more out of inertia than anything else.
Avoided it in legacy code as I donât want to get bitten by âoff by 1â errors in string handling.
Var = Dim .. it was a pointless change, IMO
Thereâs no need to use Var, itâs completely optional. So no need to beat Xojo.
The LLMs are clever enough to differentiate between var and dim. Make a coding best practices and say âuse this documentâ.
In my experience, the LLMs get confused as to whether the code they are reading or writing is API2. I was just wondering that if they saw it contained Var, they would have a hint that it was API2. Of course, it is possible to modify code that was written using API1 and just change Dim to Var, but I would think that would not be common among the holdouts who do not want to move to API2.
I was just wondering about the impact of the code that has been made public, not code that the LLMs do not have access to.
Var and Dim for me kind of signs old legacy code and newer code in a glance without reading much. So it is paradoxically useless and valuable.
If you are an API1 guy ( func3( func2( func1(str) ) ) ), keep Dim. If you adopt latest features and modern practices ( str.func1().func2().func3() ), take Var.
Iâm just going to say now that I will not be actively trying to do this. I have been using Xojo since 2000 and itâs just automatic to use Dim. In the times that I have tried to make myself use Var, I find that it slows my thinking process by 25-30% because Iâm constantly hiccuping over having to make that change.
Whereas Dim reminds me of BASIC (not a language held in high regard among computer scientists) and doesnât make much sense as it originally only referred to arrays and their dimensions, Var is the keyword used in PASCAL, the language used in my introductory computer science courses back in 1978. So when Xojo made the change from Dim to Var I happily complied.
While it doesnât make any real difference, the use of Dim in somebodyâs code suggests to me that the developer (human or AI) may not be using API2 or newer additions to the language in general.
Yeah well thatâs their problem for holding such prejudices. Xojo had the same problem when it was called RealBasic. People looked at âBasicâ and couldnât get past the idea that basic was traditionally an interpreted language like JavaScript (which also uses var BTW).
You do you. Iâm not going out of my way to trip up my brain just because you guys say so.
Your answer made me laugh.
What you wrote is very valid.
In my professional experience, I never use the DIM command.
I used a variety of programming languages. For example, Pascal (in university), Java, SQL, C++, C#, Python, among others.
For me, using DIM is synonymous with creating an array with dimensions.
In contrast, VAR defines a variable type.
These are personal interpretations. I understand Greg O., who gets the hiccups of using anything other than DIM. Thatâs why the importance of XOJO offers both options.
I think the most important thing of all is to observe how efficient the creation of the resulting binary is during compilation.
If a machine language programmer makes an algorithm more efficient than their LLM counterpart, the latter isnât performing its function in the best way.
Same here - they are synonyms so Iâm not going to bother switching. I did write some JavaScript this week, which is not a language in which Iâm comfortable or competent, and using Var there didnât trip me up any more than the rest of the language did.
You canât really get into flow state when you have to consult documentation every 30 seconds.
However, I do try to use it when I write sample code for this forum, since that code should represent current practices as much as possible.
![]()
Greg, I cannot believe that your brain would not adjust after a couple days of consistently using Var.
25% to 30% slowdown
!
Of course, your slowdown is doubtless much faster than my top speed.
As others have pointed out, both work.
Personally I use Var simply because all the other modern languages I use also use it, like Javascript and C#.
VB and Xojo are the only languages in my toolkit that can use Dim and while it is still functional, I have emotionally deprecated it.
I use both. Dim for dimensioning arrays & Var to declare variables. Makes the code a little more readable.
Until reading this thread, I thought the use of Dim in API2 projects would trigger a warning (âDim is deprecated. You should use Var insteadâ), but I just tested and itâs not the case.
I realise I made the switch to Var since it was added, just for the sake of âstaying currentâ. Iâm now using Var naturally and, when I see Dim in my reused projects, it immediately feels and reveals an old piece of code.
I would have preferred to keep Dim, if I didnât thought it would trigger a warning by mistake. But so many years after the switch, reverting to Dim would seem backward to me.
I donât know why people still regard JavaScript as an interpreted language either, all the major implementations ( JavaScriptCore, SpiderMonkey, V8, ⊠) have been using JIT compilers for a very long time now.
Because JIT cannot creates desktop applications ?
Whilst Iâve adapted to using API2, I have to say I still use dim rather than var. My first programming language was VB6, then I moved to âREALBasicâ as it was then known before it changed to Xojo. To me, dim fits with the BASIC syntax Iâm used to, although Iâm sure newer users will fall in line with var.
I remember being concerned with some of the reasonings that were given back when the change was announced though. My favourite was along the lines of âto make it easier for users of other languages like Javascript to transition to Xojoâ
I actually thought this might cause more confusion, as it overlooks the key difference that while in JS you can define a variable like var t, in Xojo you need a type unless you want a Syntax error var t as Integer.
Electron apps are JS desktop apps using all features available for a web page, as JIT, on a V8 engine (Chromium). Not a fan, but it exists and is used.