logoalt Hacker News

Prevent cognitive debt by manually retyping LLM-generated code

357 pointsby mpweihertoday at 9:32 AM292 commentsview on HN

Comments

ltbarcly3today at 8:33 PM

This is the stupidest thing I've ever heard.

"Stay in shape by walking behind your car."

thundercleezetoday at 2:58 PM

Cognitive debt is an idiotic phrase.

simondotautoday at 2:18 PM

In my current workflow, I've settled into a three tier system when coding:

1. HIGH-VALUE CODE:

I write it all myself. I will occasionally use AI for mostly mechanical changes, like cleaning up variable names or mass-changes when a function signature has changed. Either way, every line is read carefully. Sometimes this means isolating my high-value code as a library in a separate repo. Usually it's just a note in AGENTS.md, or even a well-written comment at the top of certain files. I'm not obsessive about it, though, as it can't hide from git. And learning what it's trying to change is sometimes a useful insight.

That doesn't stop me from using AI as a consultant. This is the one time I'll use a beast like Fable. Ask it to write a technical/security analysis on a section of code and damn it can pull out some impressive insights. It can't write new code particularly well, but it can inspect code like a boss. But that all stays in the chat window. (And despite being so infrequent, they ends up costing significantly more than all my other AI costs combined!)

2. BOILERPLATE/PROCEDURAL CODE:

I'll write the first draft, but once I've set the tone, I'll allow AI to build and maintain it. I keep on top of things like a senior manager, just to make sure it's not doing stupid things. Every few days I tell it to mow its own grass: AI is good at recognising its own stupidity, you just need to give it an opportunity to look.

3. TEST/HARNESS CODE:

Bring on the slop. If I get nothing else from the AI revolution, it's not having to write another stupid test unit. Nothing makes me happier than setting the AI to work writing every permutation of test I can think of. I will slop this code all day, and I won't read a single line of it. Why should I? If I ever doubt whether a particular test is correct, I'll test the test by breaking the code, not by reading the test. But I almost never catch it out. In my experience, AI is especially good at writing tests. Perhaps more than anything else.

Tests don't just take the form of a few mocks and props in a test harness. In one recent case, my project involved writing a library for the API of an obscure commercial microcontroller-powered device. I took the API documentation and made AI build me a complete simulator. I then made it write a full suite of tests using my client library within the test code. I then got it to run that test suite against real hardware and identify any inconsistencies. From there it could recursively modify the simulator until it became unreasonably good at mimicking the real hardware. I haven't read a single line of its code. But it's now core to the library's CI.

show 1 reply
phendrenad2today at 4:17 PM

Seems like a much better idea would be to build it yourself first, then have the AI do it for real? If you don't understand what you're building, you're going to get a lot of surprises when you re-type the AI-generated code and realize it subtly mistook your prompt or made decisions you didn't think to specify.

PunchyHamstertoday at 11:19 AM

...what, that's terrible advice. If you gonna waste time on that just waste time on writing the code from scratch

Alessio97today at 1:47 PM

[flagged]

kburmantoday at 3:54 PM

[flagged]

sharpnicktoday at 1:10 PM

[flagged]

chmorgan_today at 12:14 PM

[dead]

leviyitoday at 1:36 PM

[flagged]

agentmoneytoday at 12:14 PM

[flagged]

effnorwoodtoday at 12:42 PM

[dead]

_davide_today at 10:36 AM

there is a simpler way, make a complete mental model of the changes and ask questions to confirm your understanding. so much faster.