Hacker News 线索
Article URL: https://unstack.io/write-code-like-a-human-will-maintain-it
Comments URL: https://news.ycombinator.com/item?id=48859701
Points: 321
# Comments: 263
讨论摘录
- cadamsdotcom · 07/10 22:11 · 评论链接
Write yourself a /review command. That is an empty markdown file at `.claude/commands/review.md`. In it, put a checklist of things the agent should look for. When you’re ready to have your agent review the code, type `/review`. The checklist will be examined and it’ll plan out some findings to ask you if you want them fixed. Mine starts with “Enter plan mode. Examine the differences on this branch vs. main. Consider: ...” and proceeds to a bullet list of things. Any time I notice something in code review and have to get the agent to fix it.. I throw it on the list! My list is like 200 items now. Know what? Agents don’t care that they just got a wall of generic feedback, they happily look into all the bullet points. I added “ensure the new things aren...
- jwpapi · 07/11 00:16 · 评论链接
Crazy how many engineers in here just say they are using another prompt on top. From my experience that makes things worse. It does abstractions, but the wrong ones. It overcomments, confusing future calls of the LLM. To me building on multiple scalable systems this has been the most dangerous part of LLMs. On a good codebase it will work good, but it will maek it worse, so you keep using it, till it doesnt work and then you have to pay the bill and fix for what you didn’t build before. If you put an agent on a fresh codebase 2 things are often given: -> You have a mental model of the code -> The code is somewhet concise After multiple iterations both is lost and LLM performance degrades. To solve this you can regular refactor, but it’s not a nice ex...
- agentultra · 07/11 03:52 · 评论链接
Wild idea: just write code. I know. It’s an unbelievable concept in this AI era. Write code ? Isn’t that what dinosaurs did? If you expect that a human will need to read and maintain that code you might as well write it for them. You’ll get annoyed by having to read overly-verbose copy-pasted code. So will they. So write the code yourself and bringo: you’ll fix things yourself and write things in a way that makes sense for other humans to maintain. Or you can come up with a convoluted web of markdown files to try and coax your agents and loops to understand what future human maintainers will expect the code to look like. I’m not sure what path will be easier in the long run. Anyone inherit a loop-based agent-driven code base yet and have to try to un...
- davnicwil · 07/11 00:52 · 评论链接
> The next time you ask the LLM for another endpoint with the same access rules, the model won't start from first principles. It'll start from the other four copies already sitting in your repo. To be honest I'm not sure how true this is. I think it's more that there does seem to be quite a baked-in bias to repeat basic structures and not reuse (much less come up with) abstractions. So where that is the existing pattern it looks like it's keeping with that, when in reality it would often do that either way. There have been many cases where I've started a piece of work by laying down very rigid abstractions and a few examples of using them, and I explicitly prompt to not only exclusively use the specific abstraction API but also copy the way I've used...
- planb · 07/10 22:47 · 评论链接
I have good results with this prompt after every larger change: Now do a final code check. Is everything tidy and do the components adhere to the principle of separations-of-concerns. Is everything in an understandable and maintainable state? Do we make any assumptions that may not be true anymore? Is any code left over from previous edits or experiments that does not belong into the codebase? Is the documentation still representing the current state of code?
- alexpotato · 07/10 21:48 · 评论链接
There is an old quote:
"Add comments to your code under the assumption that the next person to maintain it is a homicidal maniac who knows where you live"
- egonschiele · 07/10 23:19 · 评论链接
In a similar vein, here's my favorite prompt: "Please review the tests you've written. Will the tests actually test what they're meant to? If the code breaks, will the test fail?" It's amazing how often LLMs will write tests that don't test anything.
- chickensong · 07/11 06:29 · 评论链接
The article is conflating LLM usage with bad habits. When you start a project not everything is DRY, and you don't start pulling out shared helpers until they're called for. If you're a slacker and expect the agent to magically fix everything with one-off prompting and only moving forward, it's not going to work. Agents prefer to carry existing patterns forward, just like many humans. The shared helper example from the article requires intent to refactor. If you ask the agent look for smells and refactor, it will happily assist you with that. If you ask it to add a feature, which happens to add duplication, you get a feature with duplication because you didn't specify anything else. Better yet, add tooling like static code analyzers (shout out to Cre...