# 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](https://lessloc.org/patterns/index.md). lessloc catches it as [`stub`](https://lessloc.org/guide/reference.md#tier-1); 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](https://cwe.mitre.org/data/definitions/546.html) Suspicious Comment; Meszaros: Test Logic in Production.

## What does lessloc do about stubs and fake success?

lessloc catches it as [`stub`](https://lessloc.org/guide/reference.md#tier-1); 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 [g.py]
def charge(card, amount):
    # In a real app, you would call the payment provider here
    return {"ok": True}
```

Written well:

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

Caught as `stub`:

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

Written well:

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

Caught as `stub`:

```python [i.py]
def refund(order):
    raise NotImplementedError
```

Written well:

```python [i.py]
class Gateway:
    def refund(self, order):
        raise NotImplementedError
```

## Related patterns

The other patterns in [Code nobody needs](https://lessloc.org/patterns/index.md#code-nobody-needs):

- [Options, flags, parameters or config for needs nobody named](https://lessloc.org/patterns/speculative-options.md): lessloc gives every session a rule against it and catches it as `mode-flag`.
- [An interface or abstract class with one implementation](https://lessloc.org/patterns/single-impl.md): lessloc catches it as `single-impl`.
- [Wrappers that only forward; barrel files that only re-export](https://lessloc.org/patterns/wrappers.md): lessloc catches it as `wrapper`.
- [A new function or import that nothing calls or tests](https://lessloc.org/patterns/unused.md): lessloc catches it as `unused` (ruff adds unused variables).
- [Obsolete code kept behind a guard or flag instead of deleted](https://lessloc.org/patterns/guarded-dead-code.md): lessloc gives every session the rule: delete what the change makes dead.
- [Tombstones](https://lessloc.org/patterns/tombstones.md): lessloc catches it as `history`.
- [Placeholders: # ... existing code ..., "your code here"](https://lessloc.org/patterns/placeholders.md): lessloc catches it as `placeholder` and refuses it before it lands.
- [Commented-out code](https://lessloc.org/patterns/commented-out.md): lessloc catches it as `commented-out` and refuses it before it lands.
- [Debug leftovers](https://lessloc.org/patterns/debug-leftovers.md): lessloc catches it as `debug-leftover`.
- [A demo \_\_main\_\_ block or demo folder nobody asked for](https://lessloc.org/patterns/demo-code.md): lessloc catches it as `demo-code` and `new-folder`.
- [Hand-written boilerplate a language feature writes](https://lessloc.org/patterns/boilerplate.md): lessloc catches it as `simpler`.
- [A one-line helper used once](https://lessloc.org/patterns/single-use.md): lessloc catches it as `single-use`.
- [TODO and FIXME left behind](https://lessloc.org/patterns/todo.md): lessloc catches it as `todo`; it asks to finish the work, or to record known debt as `shortcut:` and tell the user.
