Credence.Pattern.NoManualMax (credence v0.4.2)

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

Any if expression where:

  • The condition is a comparison (>, >=, <, <=),
  • One branch returns the left operand and the other returns the right, and
  • The branch returning the "greater" operand is the do (true) branch.

All four comparison operators are handled:

PatternReplacement
if a > b, do: a, else: bmax(a, b)
if a >= b, do: a, else: bmax(a, b)
if b < a, do: a, else: bmax(a, b)
if b <= a, do: a, else: bmax(a, b)