07.4 Functions and methods
Functions, methods, contracts, and calls without nullable receivers.
Functions and methods
Functions do work. Methods attach behavior to types. Contracts document what callers may assume: read the platform spec before treating this page as law.
Functions
Section titled “Functions”Top-level and scoped functions declare parameters and return types (inference may fill gaps where allowed). Keep signatures honest at API edges: internals can be messier, but not Option-as-error-swallowing messier.
Methods and receivers
Section titled “Methods and receivers”Instance methods dispatch on nominal types per method dispatch. Possibly-absent receivers use Option<T> + match, not null checks.
Contracts and effects
Section titled “Contracts and effects”Public APIs often use contracts (interfaces) with documented effects: see contracts and error handling.
Callable documentation
Section titled “Callable documentation”/// on functions may use @arg on parameters. Do not slap @arg on record fields because you were bored.
Example sketch (illustrative)
Section titled “Example sketch (illustrative)”string greet(string name) { return "hello " + name;}Exact syntax keywords evolve. Verify against spec if copy-paste fails parse.