Part 7 · Vibe Coding, With Guardrails

Three Comment Elements & Code Protection

Background, design intent, key constraints — all three required; no silent deletion of code or dependencies

THE QUESTION THIS PAGE ANSWERS

ANSWER FIRST

What is the key idea behind “Three Comment Elements & Code Protection”?

Background, design intent, key constraints — all three required; no silent deletion of code or dependencies

DECISION RULE

Turn taste into a behavior the product can repeat. The useful outcome is not a nice opinion. It is a visible rule, a small example, and a way to tell when the experience falls below the bar.

TRY NEXT

Capture one before-and-after example that shows the quality bar without extra explanation.

WATCH FOR

Polish that improves the surface while leaving the user's uncertainty untouched.

What's the problem

Code can only express "what was done." Why it exists, why it was implemented this way, what to be aware of when calling it — this information can only persist across time if written in comments. "Write good comments" is a phrase AI cannot execute on; you need to provide a fixed structure and examples.

Three-Element Structure
1

Context

What business problem this function solves and in what scenario it is called. Without context, the reader can only see the implementation, not why it exists.

2

Design Intent

Why it was implemented this way, the reasons for choosing this approach, and which alternatives were abandoned. This can't be found in git log; comments are the only carrier.

3

Key Constraints

What callers need to know: side effects, dependencies, edge conditions, and other non-obvious caveats. Without this, the next caller will step on a landmine.

Interactive Demo 1 · Same Function, Two Comment Styles

Click to switch between two comment styles for the same merge_chat_history function, and compare the amount of information each preserves.

chat/history.py
def merge_chat_history(existing: list, incoming: list) -> list: """ Merges two chat history lists and returns the merged result. """ ...
This comment restates the function name — you get the same information with a quick glance at the code. Three months later, when you wonder "why is the server authoritative?" or "why are system messages dropped?", there are zero clues.
Interactive Demo 2 · To Delete or Not — You Decide

Three real-world scenarios — judge what AI should do. Click an option for instant feedback with the relevant rule reference.

Scenario 1 · During a refactor, AI finds a block of code that handles a legacy data format. It thinks it "looks unused" and wants to delete it in passing.
Scenario 2 · After a refactor, the implementation has changed. The existing "Design Intent" comment no longer matches the code.
Scenario 3 · AI thinks fetch is lighter than axios and wants to swap out axios for fetch in the project, modifying package.json while at it.

Correct so far: 0 / 3

Two Protection Rules

Comment Protection

During refactoring, it is prohibited to delete context and design intent comments on the grounds of "the comment is too long," "the code is self-explanatory," or "cleaning up in passing." If an implementation change makes a comment inaccurate, the comment must be updated in sync. The only test: could someone taking over the code understand why it was done this way without this comment?

Code Deletion Declaration

Before deleting any existing functional code, you must explicitly inform the user with a reason. Silent deletion on grounds of "cleaning up in passing" or "looks unused" is prohibited. When you believe a code block should be removed, first annotate it with // TODO: Suggested removal - Reason: xxx and delete only after receiving approval.

Companion Rule · Error Handling

No empty catch blocks. All try/catch blocks and error branches must have substantive handling: logging + a user-visible error message, or a reasonable fallback. A bare console.log(e), pass, or // ignore all constitute silent error swallowing and are never permitted.

Key Takeaways

The mission of comments is to preserve decision-making information that code cannot express. The three-element structure gives AI a format it can follow; the protection rules prevent it from deleting them. Together, they let knowledge persist across time.

Source: This lesson's content is adapted from Chapter 7 "Code Organization and Standards" in itshen/xs_vibe_rules (rule-opensource.mdc).

Turn the feeling in “What's the problem” into a judgment

“Code can only express "what was done." Why it exists, why it was implemented this way, what to be aware of when calling it — this information can only persist across time if writte…” points out that AI has lowered the bar for making something usable. The skill readers need is noticing what is wrong and turning that feeling into an actionable requirement.

Watch the user's next action, not just the surface

Turn “What business problem this function solves and in what scenario it is called.” into observable questions: does the user know what happened, what to do next, and how to recover from an empty or failed state? Does the hierarchy make the important information visible first?

Pretty is not the same as usable

Apply “The mission of comments is to preserve decision-making information that code cannot express.” to a second screen or flow. Record one moment of hesitation and the user action after the change; observable behavior is stronger evidence than polish alone.

From “What's the problem” to “Context”

“What's the problem” grounds the problem in “Code can only express "what was done." Why it exists, why it was implemented this way, what to be aware of when calling it — this information can only persist across time if written in comments. "Write good com…”. “Context” then moves it toward “What business problem this function solves and in what scenario it is called. Without context, the reader can only see the implementation, not why it exists”. Together, they show that the lesson is not just a conclusion to remember, but a claim with conditions.

Carry the judgment into the next situation

For experience work, turn abstract impressions into user actions: did the person understand the state, find the next step, recover from an error, and want to continue?

  • “What's the problem”: Code can only express "what was done." Why it exists, why it was implemented this way, what to be aware of when calling it — this information can only persist across time if written in comments. "Write good com…
  • “Context”: What business problem this function solves and in what scenario it is called. Without context, the reader can only see the implementation, not why it exists
  • “The closing point”: Three real-world scenarios — judge what AI should do. Click an option for instant feedback with the relevant rule reference

The final “The closing point” brings the discussion to “Three real-world scenarios — judge what AI should do. Click an option for instant feedback with the relevant rule reference”. The useful thing to carry forward is knowing which judgments must be revisited when input, scale, or risk changes.

Mark as learned Your reading progress updates automatically
← PreviousNext →

Keep reading

The next useful article in the thread.

ARTICLE DISCUSSION

Leave one useful thought here.

Keep the idea that clicked, the question that stayed open, or a small note for the next learner.

Discussing Three Comment Elements & Code Protection Vibe Coding, With Guardrails
3discussionsArticle discussion · synced with the Circle
View in the learning circle
AM
Asha MorganContent editor
INSIGHTField note

I turned one judgment from this article into a small experiment I could run today. Knowing what to observe next is more useful than simply remembering the conclusion.

ARTICLE DISCUSSION7 helpful
LH
Lin HarperIndie developer
INSIGHTInsight

After reading this, I first looked for the conditions behind the idea instead of copying the method into a project. That order made the later trade-offs much clearer.

ARTICLE DISCUSSION5 helpful
KM
Kiki MooreProduct operations
QUESTIONQuestion

When this judgment reaches real work, which constraint should be added first? I am curious which step matters most between reading and the first practical attempt.

ARTICLE DISCUSSION4 helpful