· 5 min read ·

The House Edge in AI-Assisted Coding

Source: hackernews

The gambling analogy for AI-assisted coding that circulates periodically resonates because it captures something real about the experience: you sit down, describe what you want, and either walk away with working code or spend the next two hours debugging something that looked right. The randomness feels genuine.

But the analogy is imprecise in a way that matters. At a casino, the variance comes from mechanisms you cannot influence: the shuffle, the RNG, the house rules. In AI coding, the variance comes from how well your task maps to the model’s training distribution. That is a learnable signal. You can, in a meaningful sense, count the cards.

What creates the variance

Large language models generate code by sampling from a probability distribution over tokens, conditioned on your prompt and context. The temperature parameter controls how peaked or flat that distribution is. At temperature 0, the model always picks the most probable next token, giving you deterministic output. At higher temperatures, it samples more broadly, which is why the same prompt gives different answers across sessions.

Most production coding tools use moderate temperatures to balance creativity with reliability. This means the model is not deterministically wrong or right; it is wrong in proportion to how far your task sits from the center of its training distribution.

The training distribution is the key variable. Models like GPT-4 and Claude were trained on code that existed before their knowledge cutoffs. They have dense, overlapping exposure to common patterns: REST API handlers, database queries, string manipulation, standard sorting algorithms. For these tasks, the probability mass is concentrated on correct solutions, and the model reliably lands there.

The variance climbs sharply when you ask about something sparse in the training data: a library released last quarter, an obscure platform API, a domain-specific constraint your codebase has that no public code shares. The model does not know it does not know. It generates confident, structurally plausible code because confidence is a property of the generation mechanism, not a reflection of epistemic certainty.

The empirical picture

GitClear’s 2024 analysis of over 200 million lines of code found that code churn, meaning code written and then reverted or modified within two weeks, roughly doubled between 2022 and 2024, tracking the rise of AI-assisted development. They also found that “moved code,” which typically signals deliberate refactoring, declined while “added code” increased. The pattern is consistent with developers accepting AI output faster than they can verify it.

A 2023 Stanford study found that participants using GitHub Copilot wrote significantly more insecure code than those who did not, and were more confident that their code was secure. The security issues were not random; they clustered around known antipatterns in the training data: SQL string formatting, buffer handling, authentication edge cases. The model had learned to replicate human mistakes at scale.

This is not the model being bad. It is the model functioning exactly as designed: as a distribution estimator, not a correctness oracle.

Where the variance is high and where it is not

Tasks where AI coding earns its keep share a common structure: the correct solution is common in open-source code, the constraints are fully specified in the prompt, and you can verify the output quickly.

Generating boilerplate for a Discord bot command handler, writing a regex for a well-defined format, scaffolding a standard REST endpoint, converting between data formats: these are high-expected-value tasks. The model has seen thousands of examples. The prompt fully constrains the solution. A smoke test takes thirty seconds.

Tasks where AI coding carries real risk have the opposite structure: the correct solution depends on context the model cannot see, the constraints are implicit rather than stated, or the failure mode is subtle.

When I was building a Discord bot with complex role-management logic, the model generated code that was structurally correct but silently failed when multiple role-change events fired in rapid succession. The race condition was not visible in a simple test. The model had no way to know that my bot’s architecture made this event pattern common. Debugging it took longer than writing it from scratch would have.

For systems programming, the failure modes are worse. Memory layout, alignment requirements, lock-free data structures, and SIMD intrinsics all require reasoning about invariants that are not captured in the surrounding code. The model can produce something that compiles and passes basic tests while being wrong about cache line boundaries or memory ordering semantics. It looks right because the structure is familiar; it is wrong because the constraints are invisible.

The review stage is where the risk lives

Framing generation as the gamble misidentifies the moment of risk. Generation is just sampling; nothing is lost yet. The gamble is accepting output you have not verified.

A better analogy than a casino is buying components from an unmarked supplier. Some are exactly what you need. Some are subtly defective in ways that will not surface until assembly. The variance is not in what you receive; it is in whether you inspect carefully before installing.

Developers who get burned by AI coding share a consistent failure pattern: they accept large blocks of generated code, run a quick smoke test, and move on. The model’s confident, professional-sounding output creates an anchoring effect. The structure looks familiar; the test passed. Deep review feels disproportionate to the apparent quality.

Developers who use AI coding effectively treat every generated function the same way they would treat code from an unknown external contributor. They read it. They consider the edge cases it might miss. They test it against their actual constraints, not just the happy path.

Counting cards

Knowing when AI output will be reliable is learnable, and the signals are consistent enough to act on.

High-confidence indicators: the API is stable and widely documented, the task is self-contained and stateless, the prompt fully specifies the constraints, and you can write a complete test in under a minute. For these tasks, accepting AI output with a careful read is defensible.

Low-confidence indicators: the library is recent, the task involves shared mutable state or concurrent event handling, correctness depends on invariants elsewhere in your system, or the failure mode is behavioral rather than a crash. For these tasks, generated code is a starting point. Read every line. Test the edge cases explicitly. Consider whether writing it yourself would take less time than a rigorous review.

The model’s hedging language is an unreliable signal in either direction. It will preface wrong answers with confident preambles and correct answers with unnecessary caveats. Tone is not a proxy for accuracy.

The expected value calculation

“AI coding is gambling” is accurate as a shorthand for why productivity gains from these tools are unevenly distributed. Developers reporting large wins are usually working on tasks that map well to the training distribution: greenfield web services, standard CRUD operations, documentation, test scaffolding. Developers reporting neutral or negative outcomes are usually working at the edges: novel domains, complex stateful systems, security-critical code.

The tool is not broken in either case. The expected value of a bet depends on the odds of the game you are playing. Using identical strategy at blackjack and keno is how you lose money.

Knowing the variance profile of your task before you start prompting is what separates using AI as leverage from using it as a coin flip. The gambling metaphor holds; the implication that the odds are unknowable does not.

Was this interesting?