Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:1ay1 Agentty Table Driven Design

From Leeroopedia
Knowledge Sources
Domains Architecture, Configuration
Last Updated 2026-10-28 14:00 GMT

Overview

Drive behavior from a data table (array of descriptors) rather than from scattered switch/if chains, so that adding a new case is a one-line table entry rather than a multi-file code change.

Description

The Table_Driven_Design heuristic replaces switch statements, if-else chains, and scattered conditionals with a single data table (an array of descriptors or a map). Each table entry describes one case (its key, its behavior, its metadata). The code that processes the table is generic — it looks up the entry and applies the descriptor. Adding a new case is adding a row to the table, not adding a branch in N places. This centralizes the case definitions and makes the set of cases discoverable.

In agentty this appears in: the credential vault descriptors (`vault.hpp`) which define credential store behavior as a table of descriptors; and the settings registry (`settings_registry.hpp`) which defines all user-facing settings as a single table.

Usage

Apply this heuristic when a function has a switch or if-else chain over a known set of cases, and new cases are added periodically. Replace the chain with a `constexpr` or static table of descriptors, and a generic processor that iterates the table. Each new case is a new table row.

The Insight (Rule of Thumb)

  • Action:** Replace switch/if-else chains with a data table of descriptors + a generic processor.
  • Value: New cases are one-line table entries; the set of cases is discoverable in one place.
  • Trade-off: Table entries must be uniform (same fields); but eliminates scattered, duplicated case-handling code.
  • Compatibility: Pairs with Heuristic:1ay1_Agentty_Single_Source_Of_Truth — the table is the single source of the case set.

Reasoning

A switch statement scatters case-handling across the codebase: the same set of cases appears in multiple switches, and adding a new case requires finding and updating every one. A table centralizes the cases: each case is defined once in the table, and the generic processor handles them uniformly. Adding a case is adding a row — one line, one location, no risk of forgetting a switch branch. The table is also self-documenting: the set of supported cases is visible at a glance, rather than buried in switch logic spread across files.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment