The if() function evaluates all its arguments, regardless of the value of the first argument. This is bad.
An example of badness is if(A1,webservice(),"-"). If A1 is false, the URL should not be accessed. URL sites can and often changes state on access.
Fix: The second two arguments of if() should only be evaluated depending on the state of the first argument, rather than evaluating both and then choosing.
(In reply to libreoffice from comment #0)
> The if() function evaluates all its arguments, regardless of the value of
> the first argument.
Are you sure?
A simple test with formula "=IF(0, 1/0, "Good")" shows that the "1/0" argument is not evaluated, otherwise it would give a "#DIV/0!" error. Also from my understanding (see bug 111675) Calc's IF() shortcuts the evaluation of arguments, but IFS() doesn't.
So if IF() function is evaluating both second and third argument for you, please provide a sample document for testing.
After carefully constructing a test case, I was unable to reproduce what I thought was happening. Change to invalid, I guess.
Here is where I see this potential bug:
The website Alpha Vantage (alphavantage.co) allows five stock quotes per minute.
I have a spreadsheet with several instances of if(<VAR>,webservice("http://alphavantage.co/....","no-quote-yet") and the <VAR> cells set to zero. As soon as I turn on "Allow Updating", the five Alpha Vantage quotes are consumed. This means that turning on "Allow Updating" evaluated the second "webservice()" argument, regardless of the value of the first argument.
If <VAR> is zero when the spreadsheet is opened, then the second argument is not evaluated when "Allow Updating" is turned on. However, is <VAR> is 1 when the spreadsheet is opened, then set to zero before "Allow Updating", then the second argument is evaluated.
Thank you for reporting the bug. Please attach a sample document, as this makes it easier for us to verify the bug.
I have set the bug's status to 'NEEDINFO'. Please change it back to 'UNCONFIRMED' once the requested document is provided.
(Please note that the attachment will be public, remove any sensitive information before attaching it.
See https://wiki.documentfoundation.org/QA/FAQ#How_can_I_eliminate_confidential_data_from_a_sample_document.3F for help on how to do so.)
Created attachment 167685 [details]
Calc file with bug demonstration
[Automated Action] NeedInfo-To-Unconfirmed
Created attachment 168714 [details]
IF() with LOGGER() function
The claim is simply not true, the paths in IF() are not evaluated unconditionally.
Attached is a document with a BASIC macro function LOGGER() that increments a static variable each call and returns the value. In cell A1 is a formula
where if B1 is 0 or empty LOGGER() is not called and "no" is returned, otherwise (numeric B1 <> 0) LOGGER() is called and the overall call count is returned by IF(). With B1 0 or empty hit F9 a few times on cell A1 or reinput 0 in B1 repeatedly, then enter 1 in B1 and see A1 is incremented by just one of the previous value; toggle and repeat.
However, a call to WEBSERVICE() accesses the URI more than once, for example once with an OPTIONS request, then with a HEAD request and finally the GET request. If Alphavantage counts each request against your quota and not only the GET request there's nothing we can do about that.