Named arguments at call sites
When you call a function or constructor with two or more arguments, pass them by name:
// Do
drawReferenceBand(
chartContext = chartContext,
orientation = ChartOrientation.VERTICAL,
config = band,
textMeasurer = textMeasurer,
)
// Don't
drawReferenceBand(chartContext, ChartOrientation.VERTICAL, band, textMeasurer)
Named arguments make call sites self-documenting, prevent silent breakage when parameters are
reordered, and are mandatory for any boolean or multiple same-typed arguments (where position is
easy to get wrong).
Scope
Applies to calls with 2+ value arguments. Exempt (naming adds noise or isn't possible):
- Single-argument calls —
remember { … }, require(cond), listOf(x), it.copy().
- A trailing lambda that is the only "argument" written outside the parens —
dataList.fastForEachIndexed { i, v -> … }, Modifier.drawBehind { … }. If a call has other
value args plus a trailing lambda, name the value args: measure(text = s, style = style).
- Operators / infix —
a to b, a + b, x..y, a.coerceIn(0f, 1f) (infix-like stdlib scale
functions are fine positional).
vararg spreads and calls where the callee can't accept names (some Java interop).
- Simple geometry/value constructors are encouraged but not required when the order is a strong
convention:
Offset(x, y), Size(w, h), Color(0xFF…), CornerRadius(r, r).
Applying it
- New/changed multi-arg calls: write them named from the start.
- When you edit a file, name the multi-arg calls in the code you touch (don't rewrite the whole
file just for this).
- Commit gate: a staged diff that adds a positional 2+-arg call (outside the exemptions) is not
ready.
commit-with-stats checks for it.
Note: no formatter converts positional calls to named automatically — the parameter names come from
each callee's signature. Adopt this incrementally (every file you touch) rather than in one bulk
rewrite; the gate keeps new code compliant.
Quick check on a staged diff (manual review — the callee's real param names must be filled in):
git diff --cached -U0 -- '*.kt' | grep -E '^\+' | grep -E '\b[a-z][A-Za-z]*\([^)]*,[^)=]*\)'
1---2name: named-arguments3description: Call-site convention for the Charty codebase — use when writing or editing Kotlin in charty/ or composeApp/, and before committing. Function/constructor calls with two or more arguments must pass them by name (foo(a = x, b = y)), not positionally, for readability and safe refactoring. Trigger when adding a call, a drawer/helper invocation, or a chart composable call.4---56# Named arguments at call sites78When you **call** a function or constructor with **two or more arguments**, pass them **by name**:910```kotlin11// Do12drawReferenceBand(13 chartContext = chartContext,14 orientation = ChartOrientation.VERTICAL,15 config = band,16 textMeasurer = textMeasurer,17)1819// Don't20drawReferenceBand(chartContext, ChartOrientation.VERTICAL, band, textMeasurer)21```2223Named arguments make call sites self-documenting, prevent silent breakage when parameters are24reordered, and are mandatory for any boolean or multiple same-typed arguments (where position is25easy to get wrong).2627## Scope2829Applies to calls with **2+ value arguments**. Exempt (naming adds noise or isn't possible):3031- **Single-argument** calls — `remember { … }`, `require(cond)`, `listOf(x)`, `it.copy()`.32- A **trailing lambda** that is the only "argument" written outside the parens —33 `dataList.fastForEachIndexed { i, v -> … }`, `Modifier.drawBehind { … }`. If a call has other34 value args plus a trailing lambda, name the value args: `measure(text = s, style = style)`.35- **Operators / infix** — `a to b`, `a + b`, `x..y`, `a.coerceIn(0f, 1f)` (infix-like stdlib scale36 functions are fine positional).37- **`vararg` spreads** and calls where the callee can't accept names (some Java interop).38- Simple geometry/value **constructors** are encouraged but not required when the order is a strong39 convention: `Offset(x, y)`, `Size(w, h)`, `Color(0xFF…)`, `CornerRadius(r, r)`.4041## Applying it4243- New/changed multi-arg calls: write them named from the start.44- When you edit a file, name the multi-arg calls in the code you touch (don't rewrite the whole45 file just for this).46- **Commit gate:** a staged diff that adds a positional 2+-arg call (outside the exemptions) is not47 ready. `commit-with-stats` checks for it.4849Note: no formatter converts positional calls to named automatically — the parameter names come from50each callee's signature. Adopt this incrementally (every file you touch) rather than in one bulk51rewrite; the gate keeps new code compliant.5253Quick check on a staged diff (manual review — the callee's real param names must be filled in):54```bash55git diff --cached -U0 -- '*.kt' | grep -E '^\+' | grep -E '\b[a-z][A-Za-z]*\([^)]*,[^)=]*\)'56```