Var vs Dim

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

7 Likes

There’s no need to use Var, it’s completely optional. So no need to beat Xojo.

2 Likes

The LLMs are clever enough to differentiate between var and dim. Make a coding best practices and say “use this document”.

1 Like

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.

7 Likes

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.

6 Likes

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.

2 Likes

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.

2 Likes

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.

1 Like

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. :grin: 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.

4 Likes

:slightly_smiling_face:

Greg, I cannot believe that your brain would not adjust after a couple days of consistently using Var.

25% to 30% slowdown :exploding_head: !

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.

5 Likes

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.

1 Like

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.

1 Like

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.