liveBook · Manning

Stub

As explained in Coding with AI

Stubbing is the practice of creating simplified substitute implementations so other application components can be developed or tested before the real functionality exists.

A stub is simplified placeholder code that stands in for functionality not yet implemented. Stubs let an application’s structure and flow run early; real behavior is added incrementally afterward. section 4.0 section 4.1

Use stubs to make early development more manageable:

  • Connect components early and expose compatibility problems before their full implementations exist. section 4.1
  • Let team members develop components in parallel by simulating dependencies. section 4.1
  • Establish interfaces with empty functions, method signatures, dummy returns, and TODOs; ensure the stubbed application runs before filling in behavior. section 4.1.1
  • Stub one feature at a time and avoid speculative interfaces for features that may never be built. section 4.1.1

Database placeholder

A DatabaseManager can provide connect_to_database() and fetch_data() before it connects to a real database. Placeholder messages and dummy values allow dependent code to be tested; each method can later be replaced with a real implementation. section 4.1.1

class DatabaseManager:
    def __init__(self):
        pass

    def connect_to_database(self):
        # TODO: Implement this method to connect to the database.
        print("Connecting to the database...") # Placeholder
        return True # Simulate successful connection

    def fetch_data(self, query):
        # TODO: Implement this method to fetch data from the database.
        print("Fetching data...") # Placeholder
        return [] # Simulate empty result set

This listing shows a small Python class whose methods declare a database-facing interface while returning controlled placeholder results. section 4.1.1

AI can accelerate the initial skeleton: extract requirements, turn them into user stories, then request feature-organized classes and method stubs. Treat generated structure as a suggestion—validate requirements and deliberately keep, revise, or reject the output. section 4.5 section 4.2 section 4.6

How Coding with AI covers it

How deep it goes
Defines stubs, demonstrates dummy database behavior, and gives a strategic checklist without implementing real dependencies.
Examples
Demonstrates a Python DatabaseManager with placeholder database connection and query methods returning dummy values.
What you can do after
Build it from scratch by creating runnable feature stubs, organizing interfaces, and progressively replacing placeholders.
How it connects
Connects requirements, user stories, interfaces, TODOs, YAGNI, generative AI, and Flask application structure.

Also explained in

Compare how 10 books explain stub →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Coding with AI. The section links point to the parts of the book it draws on.