Named Arguments
Functions with two or more parameters of the same or similar types, or where parameter order is non-obvious, should use a named-argument object instead of positional parameters.…
$ aoe install @team/pattern-named-arguments Projection
Always in _index.xml · the agent never has to ask for this.
NamedArguments [pattern] v1.0.0
Functions with two or more parameters of the same or similar types, or where parameter order is non-obvious, should use a named-argument object instead of positional parameters. Named arguments are self-documenting and immune to argument transposition bugs.
Loaded when retrieval picks the atom as adjacent / supporting.
NamedArguments [pattern] v1.0.0
Functions with two or more parameters of the same or similar types, or where parameter order is non-obvious, should use a named-argument object instead of positional parameters. Named arguments are self-documenting and immune to argument transposition bugs.
Label
Named-argument objects over positional parameters
Problem
// Positional — easy to swap args silently:
createUser('Alice', 'admin', true, false);
// name role active verified — or was it verified first?
Solution
// Named — order does not matter; missing keys are a compile error:
createUser({
name: 'Alice',
role: 'admin',
active: true,
verified: false,
});
function createUser({ name, role, active, verified }: CreateUserArgs): User { ... }
Loaded when retrieval picks the atom as a focal / direct hit.
NamedArguments [pattern] v1.0.0
Functions with two or more parameters of the same or similar types, or where parameter order is non-obvious, should use a named-argument object instead of positional parameters. Named arguments are self-documenting and immune to argument transposition bugs.
Label
Named-argument objects over positional parameters
Problem
// Positional — easy to swap args silently:
createUser('Alice', 'admin', true, false);
// name role active verified — or was it verified first?
Solution
// Named — order does not matter; missing keys are a compile error:
createUser({
name: 'Alice',
role: 'admin',
active: true,
verified: false,
});
function createUser({ name, role, active, verified }: CreateUserArgs): User { ... }
Relations
related: [@team/pattern-builder-over-options-bag, @team/rule-no-default-export, @team/principle-readability-over-cleverness] enhances: [@team/principle-readability-over-cleverness]
Label
Named-argument objects over positional parameters
Problem
// Positional — easy to swap args silently:
createUser('Alice', 'admin', true, false);
// name role active verified — or was it verified first?
Solution
// Named — order does not matter; missing keys are a compile error:
createUser({
name: 'Alice',
role: 'admin',
active: true,
verified: false,
});
function createUser({ name, role, active, verified }: CreateUserArgs): User { ... }
Enhances
- @team/principle-readability-over-cleverness
Source
aoe-engine/examples/coding-style/primes/compiled/@team/pattern-named-arguments/atom.yaml