Heres what we want for v2.5.6, Tom:
I have strong reservations about the "with" command. It looks nice on the outside, but it really is horrible. I've worked with it in Delphi (for my day job) and it has subtle issues that can create nasty bugs that take ages to track down.
The problem is that you can't look at a "with" statement code by itself and know exactly what it does.
For example:
function SumWidgetBMI#(SWidget widgets())
dim i, sum#
for i = 0 to arrayMax(widgets)
with widgets(i)
sum# = sum# + weight# / (height# * height#)
end with
next
return sum#
end function
You might think that calculates the BMI of each widget, sums them up together and returns the result.
Problem is that you don't actually know for sure unless you go and look at the definition of SWidget. If you're working on a decent sized project, the definition of SWidget could be a long way from the code that you're writing (or in a different file altogether).
What's worse, is if you come along and make some seemingly innocent changes to SWidget later, say from:
struc SWidget
dim name$
dim weight#, height#
end struc
to:
struc SWidget
dim name$
dim weight#, height#
dim accountBalance#(10) ' Account balances
dim sum# ' Sum of account balances
end struc
Now all of a sudden your program starts printing out weird totals. Your SumWidgetBMI function always returns 0, and seemingly random values appear in the sum# field of the SWidget.
This is because now "sum#" inside the "with" statement is referring to the sum# field in your widget.
You have changed what the SumWidgetBMI function does without touching it. This is a bad thing.
Of course you don't know this. You just know your program is broken for some reason.
There's nothing to bring your attention to your SumWidgetBMI function because:
1. It still compiles and runs
2. It worked fine when you originally wrote it and tested it
3. You haven't changed it
4. You may not have noticed it going wrong straight away. You might have made a lot of other changes to the code before the bug surfaces.
If you have a lot of functions in your program, it can take a long time to track down this kind of bug. It's just not worth the pain to save a bit of extra typing. (Trust me, I've been there).
If you want to save some typing, you can use a pointer like this:
function SumWidgetBMI#(SWidget widgets())
dim i, sum#
dim SWidget& w
for i = 0 to arrayMax(widgets)
&w = &widgets(i) ' Set pointer
sum# = sum# + w.weight# / (w.height# * w.height#)
next
return sum#
end function
That's not much more typing than using a "with", and it's 100% clear when you're referring to a local variable and when you're referring to a structure field.
The meaning of the code cannot be changed by changing another part of the program. This is very important.
For those reason's, I'm not planning to implement "with" in the language.
(The other 2 suggestions sound reasonable enough though.)
-Tom