Chapter 10 · Reps

Prompts as Specifications — Reps

← Back to Chapter 10

Chapter 10 — Reps

Conditioning, not grading. This week, most reps are prompts you send. Keep a running log in reps-prompts.txt — same format as last week. Timestamp, prompt text, response summary, what you did with it.

You need:

  • Java 17 + JUnit 5.
  • Your AI assistant.
  • A text file or document where you can paste both prompts and both responses side by side. (A plain .txt file or a simple document with two headers works fine.)

Reps 1–3: Vague vs Precise

Rep 1 — Rewrite a vague prompt

Take this vague prompt:

Write a Java function that reverses a string.

Rewrite it as a four-part precise prompt (role + signature + behavior + constraints). Include at least three examples. State at least two negative constraints.

Send the vague prompt to your AI. Save the response.

Send the precise prompt to your AI in a fresh thread. Save the response.

In your log, write two sentences: what was different about the two outputs? What was the most impactful single sentence you added to the precise prompt?


Rep 2 — Same problem, three audiences

Pick this problem: given an ArrayList of Strings, return the longest one (ties broken alphabetically by Unicode order, throw if empty).

Write three versions of the prompt:

  1. Junior-flavored: asks for the method like you’re describing it casually.
  2. Senior-flavored: signature, examples, negative constraints.
  3. Test-first-flavored: three failing JUnit tests; ask the AI to produce code that passes.

Send all three (fresh threads each). Save all three responses.

Compare which response was closest to ship-ready. Log your finding.


Rep 3 — Spot the unspecified decision

Take this prompt:

Write a Java method that splits a string into words.

Without sending it, list five decisions the prompt leaves up to the AI. (Examples: what counts as a separator? what about punctuation? what about Unicode? what about leading/trailing whitespace? what about empty strings?)

Then write a precise prompt that resolves all five. Send it. Confirm the AI’s response answered each of the five questions the way your prompt told it to.


Reps 4–5: Test-First Prompting

Rep 4 — Test-first on a known problem

Write three JUnit 5 tests for a method public static int gcd(int a, int b):

@Test
void gcdOfTwoEqualsTwo() {
    assertEquals(2, Math2.gcd(4, 6));
}

@Test
void gcdHandlesOne() {
    assertEquals(1, Math2.gcd(7, 13));
}

@Test
void gcdRejectsZero() {
    assertThrows(IllegalArgumentException.class, () -> Math2.gcd(0, 5));
}

Send only the tests, plus one sentence: “Produce a Java 17 implementation of Math2.gcd that passes these tests. Use Euclid’s algorithm. No helper methods.”

Save the response. Compile. Run the tests against the AI’s code.

Log whether all three passed.


Rep 5 — Test-first reveals an under-specified test

Take the same gcd problem. Write only two tests, deliberately leaving the behavior on negative inputs unspecified:

@Test
void gcdHandlesPositives() { assertEquals(6, Math2.gcd(12, 18)); }

@Test
void gcdHandlesOne() { assertEquals(1, Math2.gcd(7, 13)); }

Send the same prompt format as Rep 4 with these two tests.

Inspect the AI’s response: how did it handle gcd(-4, 6)? Did it throw? Did it return 2? Did it return -2? Did it crash?

This is the cost of an underspecified test suite — the AI guesses. Log the guess.


Reps 6–7: Negative Constraints

Rep 6 — One prompt, three constraints

Pick this problem: count the number of distinct characters in a string.

Send two prompts:

Prompt A (no constraints):

Write a Java method that counts the number of distinct characters in a string.

Prompt B (with three negative constraints):

Write a Java 17 method public static int distinctChars(String s). Throw IllegalArgumentException if s is null. Return 0 for the empty string.

Constraints:

  • Do not use streams.
  • Do not use any helper methods.
  • Do not use regular expressions.

Compare both responses. In particular, note whether Prompt A produced a one-line s.chars().distinct().count() stream pipeline (compact but possibly not what you wanted) vs Prompt B’s plain for loop with a Set<Character>.

Both work. The point: which one matches the codebase you would actually be shipping into? That’s the senior’s call. The negative constraints are how you make it.


Rep 7 — “Do not refactor” guardrail

Take this Java method:

public static int sumOfSquares(int[] nums) {
    int total = 0;
    for (int n : nums) {
        total += n * n;
    }
    return total;
}

Send the prompt: “Add a method sumOfCubes(int[] nums) to this class. Do not refactor the existing method. Do not change its signature, body, or formatting.”

Inspect the response. Did the AI keep your method intact, or did it “helpfully” rewrite it with a Stream?

If it rewrote it: the “do not refactor” constraint was either ignored or insufficient. Try a louder version of the constraint. Iterate until the AI honors it. Log how many iterations.


Reps 8–9: Templates

Rep 8 — Use each of the five templates once

Pick five tiny problems (one per template). For each, send the prompt and save the response.

  • Implement-to-signature: Write a factorial(int n) method.
  • Test-first: Write a isPalindrome(String s) method given three tests.
  • Refactor: Take this 20-line method and shorten it without changing behavior. (Pick any method from a prior project.)
  • Explain: Take this code snippet (any AI output from a prior rep) and ask the AI to explain it.
  • Find-the-bug: Take a deliberately buggy method (you can write one with an off-by-one), ask the AI to find it.

For each, rate the response on a 1–5 scale. Log the ratings.


Rep 9 — Build your personal prompt cheat-sheet

Create a file my-prompts.txt. Paste the five templates from §10.9. For each, customize:

  • Replace placeholder language with the actual conventions of your projects (your preferred package, your preferred style, your test framework version, etc.).
  • Add notes — when you’ve used this template, what tweaks worked, what tweaks didn’t.

Save it where you can paste from it. This file is your senior toolkit; you will use it for the rest of Phase 2 and beyond.


Reps 10–11: Context Size

Rep 10 — Too little context

Pick a class you wrote in a prior project (any class with at least one private helper method). Without including the class itself, prompt the AI: “Add a new public method summarize() to this class. The class is called X and it has methods Y and Z.”

Send the prompt with no code attached. Look at the AI’s response. It almost certainly invented helpers that don’t match your real class. Note the specifics.

Now send a second prompt with the whole class attached. Compare the responses.

Log what the difference was. The cost of context-starvation is now in your hands.


Rep 11 — Too much context

Pick a 200+ line file. Send a prompt asking for a one-line bug fix to a specific method, attaching the entire file.

Look at the response. Did the AI focus on your one method? Or did it suggest changes to other parts of the file you didn’t ask for? Was the diff minimal or sprawling?

Log how to constrain better next time. The right constraint is usually a sentence like: “Only change the body of methodX. Do not modify any other method or any field.”


Rep 12 — Break It On Purpose

Six Chapter-10 mistakes. Apply each, observe, learn:

  1. Send a one-sentence prompt. Take any rep above and try it with one sentence. Note how much worse the output is.
  2. Patch instead of re-prompt. Take a wrong AI response and reply “fix it.” Repeat three times. Notice how much the AI drifts.
  3. Include conflicting requirements. Ask for “a robust, defensive implementation that doesn’t throw any exceptions.” Watch the AI try to comply with both halves.
  4. Use a sloppy signature. “A method that takes some numbers and returns a number.” Notice the AI invents a method shape for you.
  5. Forget to specify the Java version. Ask for code without saying “Java 17.” Notice if the AI uses features from older or newer versions you didn’t want.
  6. Don’t read the response carefully. Send a prompt. Skim. Ship. Then re-read carefully. Find what you missed.

Each of these is a Phase 2 student’s most common mistake. Make them on purpose. Internalize.


Done? One Last Thing.

Open your my-prompts.txt from Rep 9. Try to use it on a problem you haven’t seen yet — any small Java task. Time yourself.

If your cheat-sheet shaved real minutes off the prompting process, you’re done. If not, edit the cheat-sheet until it does.

The senior’s toolkit is the tool the senior actually reaches for. Make yours reachable.


Up next: Project 10 — Project 10: Two Prompts, Two Outcomes.