liveBook · Manning

YAGNI principle

As explained in Build High Value Software Systems

A software design discipline that delays adding structure until a concrete requirement demonstrates the need for it.

A small change to a legacy system can turn into a large pull request when developers build for imagined requirements. Unused notification channels, plugin systems, and extension points add code that future changes must navigate, review, test, and maintain. section 7.3.1

YAGNI—“You Aren’t Gonna Need It”—means letting a real requirement pull the next design decision. Start with the structure needed now. Add an abstraction when current work demonstrates its value, not merely because future variation is possible. section 7.3.1 section 7.6

Let notification requirements lead

For email-only order confirmations, one function sends the email. When high-value orders also require SMS, a conditional handles that requirement. When several channels are actually needed, channel selection and shared message formatting earn their place. A plugin architecture for channels nobody uses would reverse that sequence. section 7.3.1

Listing 7.8 Iteration 3: Four channels. The pattern earns its place.
HIGH_VALUE_THRESHOLD = 5000
 
def notify_order_confirmed(order):
    message = format_confirmation(order)
    for channel in channels_for(order):
        channel(order, message)
    order.mark_notified()
 
def channels_for(order):
    yield send_email
    if order.total >= HIGH_VALUE_THRESHOLD:
        yield send_sms
    if order.customer_has_app:
        yield send_push_notification
    yield send_slack
 
def format_confirmation(order):
    return {
        "subject": f"Order #{order.id} confirmed",
        "body": f"Order {order.id} for {order.customer_name}, total {order.total}.",
    }

The multichannel listing makes the later design concrete: notification channels are selected and invoked after the requirements have expanded beyond one or two cases. section 7.3.1

Before adding structure, ask:

  • What current requirement needs it? A possible export format or warehouse integration is not the same as an existing one. section 7.3.1
  • Would a smaller change suffice? A conditional can serve a second notification channel without a plugin system. section 7.3.1
  • Is the abstraction needed on the path changing today? Create a test seam for the test at hand rather than redesigning an entire dependency layer. section 7.3.2

The same question applies beyond functions and interfaces: avoid splitting services in anticipation of demand. YAGNI is not a ban on patterns; it is a reason to make them answer demonstrated friction. section 11.0 section 7.3.2

How Build High Value Software Systems covers it

How deep it goes
Works through notification iterations from one function to a conditional to multichannel selection.
Examples
Contrasts unused notification plugins with email-only, email-and-SMS, and multichannel implementations.
What you can do after
Practice/perform it by making the smallest current change and deferring extension points until a requirement justifies them.
How it connects
Links Lean pull systems and design patterns to test seams that introduce only the abstraction a current change needs.

Also explained in

Compare how 5 books explain YAGNI principle →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build High Value Software Systems. The section links point to the parts of the book it draws on.