Functions
Cheat sheet · https://pcornel.dk/topic.php?topic=5217
Answer
Functions package reusable behavior behind an explicit input/output contract. Reliable functions minimize hidden state, expose failures and separate pure transformation from external side effects where practical.
Remember
- Function returned ≠ side effect verified; a return value can describe intent rather than real target state.
- Reusable ≠ context-free; hidden globals, environment and working-directory assumptions reduce portability.
- No exception ≠ valid result; functions can return partial, empty or sentinel values that callers must validate.
- Small function ≠ single responsibility automatically; unrelated side effects can still be hidden behind a short wrapper.
First checks
declare -F— Bash functionsGet-Command -CommandType Function— PowerShell functions- Unit tests per function — testability
Verify in this order
input → function → output
Where it usually breaks
A function return proves only what the function chose to report; it does not prove hidden dependencies or external side effects reached the intended state.
Script/input → command/module binding → local/remoting session → request accepted → command result → target object read-back → effective runtime state → workload.
Functions scripting boundary map
| Boundary | Healthy evidence | Suspicious evidence |
|---|---|---|
| Input / runtime | Effective inputs, runtime, working context and dependency versions are explicit | Hidden defaults, stale environment, wrong interpreter/path or unvalidated input |
| Logic / execution | Branch/function/module decisions and external actions expose per-operation results | Swallowed failures, shell reinterpretation, blind retries or last-result-wins behavior |
| Result / proof | Exit/exception/log evidence is correlated with independent target read-back | Process success or printed output treated as target success |
| Recovery / troubleshooting | First failed boundary is preserved, changed minimally and retested | Random edits, catch-all suppression or evidence destroyed before diagnosis |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=5217