Use it when configuring, checking or troubleshooting Functions in Scripting.
Functions · Scripting
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.
1. Functions organise reusable logic.
2. Small, single-purpose.
3. Local variables.
4. Return codes/values clearly.
5. Test them.
input → function → output
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Operational evidence path Verify boundary
caller/input contract → validation → local logic/dependencies → optional external side effect → return/exception → caller evaluation → target verification
Healthy evidence: functions have explicit contracts, narrow scope, predictable failure behavior and observable side effects that callers verify.
Step 2 Failure modes and next checks Narrow the fault
Suspicious evidence: hidden globals, implicit returns, exceptions converted to success values, unrelated side effects or callers that ignore returned error state.
Step 3 Common mistakes Narrow the fault
- Functions with side effects.
Step 4 Where it fails Narrow the fault
Where Functions usually goes wrong: input/output contract, side effects, error propagation, determinism and testability.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- 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.
declare -F— Bash functionsGet-Command -CommandType Function— PowerShell functions- Unit tests per function — testability
ReferenceWhat it is1 section · depth on demand
Core model
Define parameters and return shape, validate assumptions at the function boundary, keep scope local, surface exceptions or error results deliberately and make external side effects observable to the caller.
ReferenceImportant terms & boundaries2 sections · depth on demand
What this shows and what it does not
A function return shows only what the function chose to report, but it does not show hidden dependencies or external side effects reached the intended state.
In depth
Functions package a piece of logic under a name with parameters and a return value, so it can be reused, tested and read easily. Splitting a script into functions is the first step from a quick script to maintainable code.
def vlan_config(vlan_id: int, name: str) -> str:
if not 2 <= vlan_id <= 4094:
raise ValueError(f"invalid VLAN {vlan_id}")
return f"vlan {vlan_id}\n name {name}\n"
function Get-DiskFree { param([string]$Computer) Get-CimInstance Win32_LogicalDisk -ComputerName $Computer | Select DeviceID, FreeSpace }
Keep functions small and focused, avoid changing global variables inside them, and validate parameters at the top.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Scripting > Functions. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://docs.python.org/3/ · confidence 94%Terms & aliases
Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.
Quick lookup tables
Functions scripting boundary map
Fast input, runtime, execution, result and verification boundaries for Functions.
| 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 |
Deep reference
Healthy vs suspicious evidence
Output interpretation
For Functions, rely on structured fields and stable IDs (input/output contract, side effects, error propagation, determinism and testability) rather than text formatted for display.