#softwareArchitecture #philosophy

Lately I've been implementing declarative predicates:

person.do_with_name(
name -> act_on_name
)

and its sibling:

person.do_with_name(
name -> act_on_name,
() -> warn_name_is_missing
)

and I like that a lot.

But it has 2 obvious draw-backs.

1. Deep nested stacks;
2. Code running off the side of the screen.

Draw-back 2 is fixed by moving the actions and warnings into their own procedure.

Draw-back 1 is more elusive.

Unless the #programming #language #compiler recognizes declarative predicates and flattens them into if-then-else structures (which turn into if-goto assembler), this could lead to a huge stack full of procedures that are just idling about, waiting for a nested procedure to get released.

It's the exact opposite of #guardClauses which short-circuit execution by failing fast, and return to their caller quickly, freeing that stack frame instantly.
In the #java #programming #language, declarative predicates are available in standard objects like Optional:

Optional.of(name).ifPresentOrElse(
content -> actOnName,
() -> warnOnMissingName
);

In #rustlang, they are available in standard objects like Option:

match name {
Some(ref content) => act(content)
None => warn("no content")
}

In #dark these probably don't exist, as it favors guard clauses.