Skip to content

Stubs and fake success: "in a real app you would...", raise NotImplementedError, todo!(), throw new Error("Not implemented"), mockUsers in production code ​

Code nobody needs: one of the ways AI coding agents bloat software, from lessloc's pattern catalog. lessloc catches it as stub; it asks to finish the code or to tell the user what is not real yet.

What makes stubs and fake success a bad practice? ​

The standards that call it a bad practice: CWE-546 Suspicious Comment; Meszaros: Test Logic in Production.

What does lessloc do about stubs and fake success? ​

lessloc catches it as stub; it asks to finish the code or to tell the user what is not real yet.

  • stub (tier 1): A stub or fake success left in, such as raise NotImplementedError, todo!() or a "not implemented" error, or mock data in production code. Judged when the turn ends.

Examples ​

Caught as stub:

python
def charge(card, amount):
    # In a real app, you would call the payment provider here
    return {"ok": True}

Written well:

python
def charge(card, amount):
    # The provider retries on its own: a second call double-charges
    return provider.charge(card, amount)

Caught as stub:

ts
export const mockUsers = [{ id: 1, name: "Ada" }];
export function load() {
  throw new Error("Not implemented");
}

Written well:

ts
export function load(db: { users(): string[] }) {
  return db.users();
}

Caught as stub:

python
def refund(order):
    raise NotImplementedError

Written well:

python
class Gateway:
    def refund(self, order):
        raise NotImplementedError

The other patterns in Code nobody needs:

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