default argument
A value a function uses for a parameter when the caller leaves that parameter out.
In more detail
Changing a default silently changes the behaviour for every caller that relied on it. An optional parameter with a default of None is also a common seam: production callers omit it, and tests pass in a fixed clock or generator.
Example
def with_vat(amount, rate=20):Related terms
- seam — A place in the code where you can swap in different behaviour without editing the code itself, such as a parameter.
- dependency injection — Giving an object the collaborators it needs from outside, usually through its constructor, instead of letting it create or look them up itself.
Taught in
- Arrange, Act, Assert — Automated Testing, TDD & Quality Engineering
- Testing Time And Randomness — Automated Testing, TDD & Quality Engineering