Preserve Whole Object

Compare
Symptom
Human

A function call that pulls several fields out of an object to pass them in — `f(room.lowTemp, room.highTemp, room.humidity)` instead of `f(room)`.

Agent

The agent sees call sites unpacking multiple fields from an object to pass to a function; adding any field the function later needs touches every call site.

Goal
Human

Instead of pulling several values out of an object to pass them in, pass the object itself.

Agent

The function takes the object; the agent updates one place when the function needs new fields.

Before the refactoring

if (room.lowTemp < range.low || room.highTemp > range.high) { /* ... */ }

After the refactoring

if (range.includes(room)) { /* ... */ }
Example source: Illustrative example written for this site, not a quotation from any source.
Pressure
Human

Adding a new field that the function needs touches every call site; the function's contract is verbose and shifts every time it grows.

Agent

Every call site is a coordination point; the agent verifying a signature change must update every unpacking explicitly.

Tradeoff
Human

Passing the whole object adds coupling to its full surface — only do this when the called function might reasonably need other parts of the object.

Agent

Passing the whole object couples the function to the object's full surface; the agent reasoning about the function must consider what other fields it might quietly read.

Relief
Human

Signatures shrink; adding a needed field is internal; consumers don't have to plumb new arguments through.

Agent

Signatures shrink; adding a needed field is an internal change; the agent reasons about one parameter at every call.

Trap
Human

Passing whole objects when the function only needs one field — introduces unnecessary coupling to the object's full surface.

Agent

Passing whole objects when only one field is needed couples the function to the object's full surface the agent must consider as the function's input scope.