User Tools

Site Tools


working_with_ai:when_not_to_trust_ai

7. AI‑Generated Code: When to Trust It, When to Rewrite It

AI drafts.
We decide what survives
.

AI can produce PHP quickly,
but not all output deserves to survive.
Some drafts are solid foundations
while others are better thrown away and rebuilt with clarity.

This page helps us develop the quiet judgment that tells us when to keep AI’s work
— and when to start over.


1. Trust AI When the Shape Is Right

AI’s code is trustworthy when:

  • the data shape is clear and stable
  • the boundaries make sense
  • the responsibility is focused
  • the flow is predictable
  • the architecture matches the request

If the structure feels coherent, we can refine the details.

Signal of trust:
We can describe the code in one or two sentences
without apologizing for it
.


2. Trust AI When It Uses Modern PHP With Purpose

AI is on the right track when modern features appear
but only because they express meaning,
not because they “look modern.”

Examples of good signals:

  • readonly on objects that truly don’t mutate
  • enums that represent real domain concepts
  • attributes tied to an actual system
  • typed properties that clarify intent
  • small, focused service objects

If the features match the architecture,
the draft is worth keeping
.


3. Trust AI When the Code Is Boring

This is one of the strongest signals.

Good AI‑generated code is:

  • predictable
  • unexciting
  • straightforward
  • easy to read
  • easy to explain

If the code feels “boring in the right way,”
it’s usually safe
.


4. Rewrite When the Shape Is Wrong

If the architecture is off, don’t fix it
— replace it.

Rewrite when we see:

  • arrays pretending to be objects
  • inconsistent return types
  • unclear boundaries
  • mixed eras of PHP
  • static methods used as shortcuts
  • deeply nested arrays
  • unclear responsibilities

Trying to patch a bad shape
only makes it worse
.


5. Rewrite When AI Over‑Engineers

AI sometimes produces:

  • factories for trivial objects
  • service locators
  • unnecessary interfaces
  • abstract classes with one implementation
  • configuration arrays for simple behavior

If the code feels ceremonial or noisy,
start over with a simpler request
.


6. Rewrite When AI Imports Patterns From Other Languages

AI often drifts into:

  • async/await
  • decorators
  • dataclasses
  • pattern matching
  • TypeScript‑style inference
  • Java‑style interfaces

If the code feels foreign to PHP,
rewrite it with a clear constraint:

“Use PHP 8+ idioms only.
No patterns from other languages.”

7. Rewrite When the Code Is Hard to Explain

A simple test:

“Can I explain this code to another developer in one breath?”

If the answer is no, the architecture is wrong.

Rewrite from the top.


8. Rewrite When the Code Fights the Mental Model

Modern PHP has a quiet rhythm:

  • clear shape
  • explicit boundaries
  • predictable flow
  • meaningful features
  • minimal ceremony

If AI’s draft breaks that rhythm,
it’s easier to start fresh than to salvage it.


9. Trust AI for Drafting, Not Designing

AI is excellent at:

  • generating boilerplate
  • filling in predictable patterns
  • refactoring within a known structure
  • producing alternatives
  • rewriting for clarity

AI is not excellent at:

  • designing architecture
  • choosing boundaries
  • defining data shape
  • deciding what matters

Trust AI for speed.
Trust yourself for structure
.


Summary

Trust AI when:

  • the shape is clear
  • the architecture matches the intent
  • modern features are used with purpose
  • the code is boring and predictable

Rewrite when:

  • the shape is wrong
  • the architecture is noisy
  • patterns come from other languages
  • the code is hard to explain
  • the mental model is broken

AI drafts.
We decide what survives
.


This page describes common behaviors observed in AI models when generating PHP code.
These patterns are not guarantees, but they are consistent enough to be useful when reviewing or guiding AI output.


working_with_ai/when_not_to_trust_ai.txt · Last modified: by editor