Chapter 11

Working with AI

The AI writes what it was trained on. You were trained on classes. So was it.
Demo: Same task, different prompt: watch the AI generate
☠ No constraints
"Build a notification system that sends email, SMS, and push notifications based on user preferences."
Lines: 0
✦ Better prompt
"Build a notification system that sends email, SMS, and push notifications based on user preferences." (prompted differently)
Lines: 0
0
Lines generated
0
Lines generated
0
Classes created
0
Classes created

What you just saw

The left panel is what every AI code assistant generates by default: a class hierarchy. NotificationService, EmailNotifier, SMSNotifier, PushNotifier, NotificationFactory, UserPreferenceManager. The AI reaches for classes because that is the dominant pattern in its training data. It generates more code because the class architecture requires more machinery: constructors, inheritance, factory methods, dependency injection.

The right panel is the same AI, given the same task, prompted differently. It generates pure functions, typed dictionaries for configuration, and a dispatch map instead of a factory. Fewer lines. No classes. The same behavior, expressed directly.

The AI is not the problem. The training data is the problem. How you prompt it changes everything. The exact prompt that produced the right panel is included with every copy of the book.

How this works: This demo visualizes AI code generation output, not timing. A default prompt produces 6 classes and an inheritance hierarchy. A better prompt produces pure functions and typed dicts. Line counts and class counts are from real AI-generated code.
← Ch.10: Testing Honest Code Ch.12: The Declarative Principle →