On Friday, 30 January 2026 at 02:24:02 UTC, Ali Çehreli wrote:
On 1/29/26 4:28 PM, kdevel wrote:
[...]
The OP's question was about how to return an empty result without wasting CPU cycles.

Sure. How to do that in a reasonable way is already clear from
the OP in which the OP wrote: "This works:" and then presents
a viable solution to that problem.

What he did not present is a "fail fast" version of such code.
"fail fast" means to stop all constructive processing and go
into the error processing path. One may debate if calling
cleanup code (destructors) is acceptable under a "fail fast"
regime (personal opinion: yes). But code that puts null or
the empty list into a chain of function calls does surely not
fall under "fail fast":

    if (fail)
    {
        return transform([]);
    }

>        FailFast also refers to some programming techniques
that cause
>        an exception to be thrown or other redirection of
control to
>        occur upon meeting certain conditions. [...]
>
>        http://c2.com/

I've been throwing exceptions for a very long time via 'throw', 'enforce', 'assert', etc. I've never heard of that definition before.

Sorry for not being able to fetch the bibliographically correct
references to that 20+ year old paper [1] by Jim Shore in IEEE
Software. First page second column:

"In contrast, a program that fails fast will throw an exception"


[1] Jim Shore: Fail Fast
    https://martinfowler.com/ieeeSoftware/failFast.pdf

Reply via email to