Skip to content

Rebuilds what the standard library or framework has: counters, flag loops, CSV, date math, argument parsing ​

Code that already exists: one of the ways AI coding agents bloat software, from lessloc's pattern catalog. lessloc gives every session a rule against it and catches it as simpler and reinvented.

What makes rebuilding what the standard library or framework has a bad practice? ​

The standard that calls it a bad practice: Bloch, Effective Java Item 59: Know and use the libraries.

What does lessloc do about rebuilding what the standard library or framework has? ​

lessloc gives every session a rule against it and catches it as simpler and reinvented. The working standard puts the standard library and the platform before new code. simpler catches hand-built counters, flag loops and range(len()). reinvented catches deep clone, UUID, debounce, slugify, CSV and flag parsing written by hand, and retry loops where the project already retries.

  • simpler (tier 2): Brute-force code with a shorter idiom: == True, an if/else that returns the condition, an index loop that only reads xs[i], .filter(...).length > 0, a catch that only rethrows, a flag loop that is any(), a hand-built counter, an __init__ that @dataclass writes, a React Effect that only sets state. ruff and clippy add more.
  • reinvented (tier 2): A hand-written version of what the standard library or an installed package does (deep clone, UUID, debounce, slugify, CSV, flag parsing), or a retry loop where the project already retries.

Examples ​

Caught as reinvented:

js
export function deepClone(o) {
  return JSON.parse(JSON.stringify(o));
}

Written well:

js
export function snapshot(o) {
  return structuredClone(o);
}

Caught as reinvented:

python
def deep_copy(obj):
    return {k: v for k, v in obj.items()}

Written well:

python
import copy


def snapshot(obj):
    return copy.deepcopy(obj)

The other patterns in Code that already exists:

Released under the Apache-2.0 license. · llms.txt