But even easier is to do instance[$ "variable_name"], as struct accessors should work with instances too
Yeah but that only works for instance variables. With a boxed variable it works with instances, locals, globals, what have you.
f it's done in the function call, all functions must be compiled in such a way that any argument could potentially be either a value or a reference/pointer, which would possibly mean additional overhead
Nah, gml is dynamically typed. It would just add one more variable variant 'ref'.
It would mean every access would need to check the variable type, but that's already the case (accessing a string is different from accessing a real).
Where overhead might appear is on assignment, where it would need to check the type. Though it's entirely possible it's already checking the type on assignment anyways. If bit, I don't think the overhead would be all that significant when compared to the rest of the inefficiencies dynamic typed languages have.
Besides even if it was in the function declaration, I would expect the same checks to be there, as a new variable type would be the simplest implementation. The alternative would be to make refs distinct from variables at compile time, effectively introducing some static typing, which I doubt gnl is equipped to deal with.
Whether it's on the declaration or the call site is interesting.
If on the call site, it's immediately clear what the side effects of the function calls are. however in the function itself, it may seem non-sensical to modify a variable unless you know it is passed in by reference (incidentally, this limits some optimization opportunities for the compiler, unless the function gets inlined or lto got really good).
Ref in the function call means it's clear inside the function why we modify a variable, but it's no longer clear in the call what the side effects would be.
I think ref types would be quite interesting, but probably too complex to deal with. In the meantime boxing solves most of these issues.
It's clear both in the function, out of the function, and even in the original variable dรฉclaration (as it's boxed) that you are using a ref.
However it does limit flexibility as now you can only use variables that have been boxed to start with. Perhaps gnl could offer some utilities around the concept of boxing, rather than introduction refs.
But this is all off topic, and I suspect this warrants a separate thread.
Incidentally I used to implement refs using arrays and the @ accessor.
(Ps, I'm just laying out my views, but since I have no ongoing GM projects, or plans for a new GM project, Im deliberately trying not to say 'keep it' or 'remove it'.)