There is a recurring programming error in Basic, when IsMissing is combined by a logical operator with a use of potentially absent variable, as in
> If Not IsAbsent(foo) And foo > bar Then ...
See e.g. code shown on the screenshot at https://ask.libreoffice.org/t/messagebox-weird-response/86789
We need a comment on IsMissing help page, discussing that this must be
> If Not IsAbsent(foo) Then If foo > bar Then ...
Imho, the question is, should Basic support short circuting in boolean expressions or not?
(In reply to Andreas Heinisch from comment #1)
I would like to see it in Basic, but this would be an incompatible change, breaking any possible existing code that relies on side effects of unconditional evaluation of all expressions.
How about introducing a new flag like OPTION EXPLICIT? So you have legacy code would be unaffected.
(In reply to Andreas Heinisch from comment #3)
This is exactly what is proposed in https://ask.libreoffice.org/t/if-conditions-continue-to-be-evaluated-even-after-the-if-has-been-satisfied/89385/. I am not opposed much, even though it feels like "do it just because we can" ;)
Yep, you are correct. The huge drawback would be that code written with this flag would not work in older versions.
I also believe that the absence of a short circuit must be written in the documentation. May be here: https://help.libreoffice.org/7.6/en-US/text/sbasic/shared/00000002.html?DbPAR=BASIC
There are many constructs of this type (except IsMissing), for example:
If IsArray(arr) And UBound(arr) >= 1 Then
Here is how Microsoft writes about it in the VBA documentation :)
Ah - thanks a lot! Indeed, the operators in Basic combine logical and bit operators - and so, before both sides are evaluated, it's impossible to resolve the result of expression. Hence, the short-circuiting is even impossible generally.