Credence.Pattern.NoManualMax
(credence v0.7.0)
Copy Markdown
Detects if expressions that manually reimplement Kernel.max/2.
Why this matters
LLMs frequently expand max(a, b) into conditional form because they
translate from languages where max is less ergonomic or unavailable
as an infix/kernel function:
# Flagged — manual reimplementation
new_current = if(current_sum + num > num, do: current_sum + num, else: num)
# Idiomatic — Kernel.max/2
new_current = max(current_sum + num, num)Kernel.max/2 is clearer, shorter, and communicates intent directly.
Flagged patterns
Only the non-strict comparison forms are flagged, because only they equal
max/2 for every input. max/2 returns its first argument on a tie, so:
| Pattern | Replacement | Flagged? |
|---|---|---|
if a >= b, do: a, else: b | max(a, b) | yes |
if b <= a, do: a, else: b | max(a, b) | yes |
if a > b, do: a, else: b | — | no |
if b < a, do: a, else: b | — | no |
The strict forms (>, <) take the else branch on a tie, which differs from
max/2 when the operands are equal in value but different in type — e.g.
max(1, 1.0) is 1, but if 1 > 1.0, do: 1, else: 1.0 yields 1.0. So they
are not rewritten.