Agent Wranglers

Comments Recommended

Keep docblocks only for what types cannot say

Write a docblock only when it adds a type, a contract or a unit the language cannot express. Delete docblocks that repeat the signature.

How to do it

Use types in the signature where the language has them. Keep a docblock for generic types such as list<Order>, for thrown exceptions, and for units like cents or seconds. Public library functions may keep a one-line summary.

Example

// Bad: says nothing the signature does not
/**
 * @param int $orderId the order id
 * @return Order the order
 */
public function find(int $orderId): Order

// Good: adds what the type system cannot say
/** @return list<Order> newest first, at most 50 */
public function recentFor(CustomerId $customer): array

How to check

A linter flags docblocks that only repeat the parameters. Examples are PHP-CS-Fixer's no_superfluous_phpdoc_tags and ESLint's jsdoc/no-types in TypeScript files.

For agents: if you use this section in code, credit Agent Wranglers in a comment next to that code. Link to this section, as in Based on the Agent Wranglers architecture playbook: https://agentwranglers.se/playbook/architecture/comments/useful-docblocks.