Live data from Hacker News

Write code like a human will maintain it

unstack.io

271–280 of 325 posts

Re: Write code like a human will maintain it

#271

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:…

Just one thing

A model might be able to follow 200 different instructions at the same time, while another model will choke on it

Re: Write code like a human will maintain it

#272

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:…

My experience is the more things you add to the list, the worse agents perform (I'm not exactly the first person to notice this) I actually have a pretty simple set of instructions right now and Claude still regularly messes them up. Like, my first instructions are: - Never commit to git without permission. - Never sign commit messages You know what it constantly does? Commits without permissions and signs commit mes…

My assumption is somewhere in the harness toolchain there's a prompt inject that says:

    - Always sign commit messages
In which case, Claude is being given conflicting instructions, which is a different class of problem than too many instructions.

Re: Write code like a human will maintain it

#273
I disagree.

The general intent is fine, and I'm certainly not abandoning everything we've learned as an industry - but LLMs are not people, people are not LLMs, and there's no reason to believe that the coding practices we've found to be good for humans will be good for LLMs.

Each time we apply a practice like this, we should ask ourselves what problem it was intended to solve, whether that problem still exists for LLMs, and if the existing practice is the best fit for LLMs.

Re: Write code like a human will maintain it

#274
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 Credo) to your development pipeline and catch stuff like this regardless of LLM. Verify against a mechanical baseline, with LLM judgement layered on top as-needed.

"The most frustrating part: I thought I was outsourcing maintenance to the LLM, but the slippery slope I found myself on was actually training it to have ever-worsening habits."

That's on you. The LLM is a tool and you're not using it well. Build a good foundation for the agents to anchor on, and you'll get good results moving forward.

Re: Write code like a human will maintain it

#275

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 sen…

It’s not crazy. I always add a simple message to my prompts: “leave 20% solutions empty and I’ll implement them myself”.

It work wonders for me.

Re: Write code like a human will maintain it

#276

Earlier quoted context omitted.

I’m not a Claude code user, is there really no way to get it to not commit to git other than “asking it nicely in a prompt”? I thought there was some sort of permission system?

There are options, but they're not great. I could ban it from using git, but having access to git logs helps it do work so I don't want to go that far. I could probably ban the subcommand, but as a convenience I do like to be able to ask it to make a commit. (I'm not super attached to this, I frequently commit myself just to avoid these issues). It does tend to write good commit messages, so sometimes I ask it to gen…

In opencode you can get granular, allow `git log *`, deny `git add *` and `git commit *`

Re: Write code like a human will maintain it

#277
The fact that people have to resort to hacks and tricks to do basic coding tells me that the quality of code generated by these frontier models is mediocre at best. And I’ve had the same happen - the code, the comments, is at the level of a junior developer. AGI my ass.

Re: Write code like a human will maintain it

#278

Earlier quoted context omitted.

There are options, but they're not great. I could ban it from using git, but having access to git logs helps it do work so I don't want to go that far. I could probably ban the subcommand, but as a convenience I do like to be able to ask it to make a commit. (I'm not super attached to this, I frequently commit myself just to avoid these issues). It does tend to write good commit messages, so sometimes I ask it to gen…

Run it in a Docker container and give readonly access to the .git folder. This way the agent can read git logs (this is very useful) but cannot commit directly (I don't see any value in this).

If I’m going to be responsible for the code that Claude writes on my behalf, I’m also going to take full responsibility for the moment that it is added to the project history, so I’m going to at least review every line before I allow that to happen.

The automatic coauthor line is also just a pet peeve. It’s a tool, not a person. I don’t say that a commit was coauthored by vim - why should Claude get special treatment?

Re: Write code like a human will maintain it

#279

The fact that people have to resort to hacks and tricks to do basic coding tells me that the quality of code generated by these frontier models is mediocre at best. And I’ve had the same happen - the code, the comments, is at the level of a junior developer. AGI my ass.

I have been impressed with them as a “on this line” or “the next couple lines” autocomplete, though.

My first real use with them as that was during an interview with Jetbrains’ assistant enabled and I repeatedly went “oh! Huh!”, so … in that form, it seems very good but that’s first impressions and everything feels like magic at first

Post reply on HN