Live data from Hacker News

Write code like a human will maintain it

unstack.io

211–220 of 325 posts

Re: Write code like a human will maintain it

#211

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

Given all the hype that LLMs have got and the valuations these AI companies are getting, I am disappointed at how even the "best" coding agents degrade over time.

WTF - I need to implement a review command to guide to do its job properly.

Can you imagine any other industry charging people money for a product like this ?

When you are charging people money - scratching the surface cannot be an excuse.

Re: Write code like a human will maintain it

#212
It might just be me, but AI has made my code more human-maintainable. They've been complaining about obsolete comments, separation of concerns, testability, global mutable state...

(Also performance and security issues, addressing which doesn't make the code more readable, but does make the program itself more robust.)

That being said... I have found them weirdly unsuitable for some tasks though, e.g. asking frontier LLMs to assist me with game development, I found that they were not able to add simple features to a simple Pong clone (nor even port a working Pong implementation) without constantly breaking things. (Yes, Pong, from 1972!)

So, I want to say YMMV, but just the past 2 weeks, my own mileage has varied very much! They seem to be extremely domain specific.

"Half the time, it works every time!"

Re: Write code like a human will maintain it

#213

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

I've been finding that they can write surprisingly elegant code, you just have to ask them to. It seems to be kind of like the old generative AI art days where you still had to add "+quality -bad" to the prompt.

Failing that they default to the most common style they were trained on. Which, at this point, is mostly code they wrote...

Re: Write code like a human will maintain it

#214

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.

My workflow is: - Write the test first, confirm it fails - Write the minimum code to make that test pass - Confirm it is green

Re: Write code like a human will maintain it

#215

Earlier quoted context omitted.

good, but this is just a verbose "make no mistakes"; it'd probably make more sense to just setup a nightly cron job that loops through the prior days' work and writes some morning tasks of the same character. The models will interpret this willynilly; but nonetheless, it's often a better than doing nothing.

It means the same thing to you, but not to the whole spectrum of people using AI. You literally see it on Reddit all the time where people are complaining about the same model either over-engineering or doing too much, vs it being requiring too much steering or not being autonomous or capable enough to hand off tasks to on its own. The reason prompting it to review its own work for loose ends, record any new undocume…

the problem is when you ask it to review it's own work in it's own context is you've already primed it to sniff it's own farts and say everythings fine.

Re: Write code like a human will maintain it

#216
Maybe we should start writing code like the LLM will maintain it. I’d be curious if there are weird optimizations that the LLM can drive that might not be things that help us humans like DRY etc.

Edit: this small things drive me crazy when I’m coding with LLM… which is basically all the time these days, but I also read all the code as well.

Re: Write code like a human will maintain it

#217

AI is so miserable for this. It's so focused on doing what you ask, it forgets that there's stuff worth doing that you didn't ask for, like defining reasonable abstractions. Getting away from stuff like this is exactly why I want to use AI. When I say "implement this for idle but active users," I _want_it to define isUserActiveIdle() and stuff these 4 conditionals in it. Having to check the generated code for stuff l…

[deleted]

Re: Write code like a human will maintain it

#218
post #197
post #142

Earlier quoted context omitted.

Unless prompted to do so, why would it? From the article: "Every shortcut you merge into your codebase is a signal about how things are done here."

Not duplicating code is literally best practice. Why would it deviate from that?

This is far from a universal best practice and heavily depends on what code it is and for what reason you are duplicating it potentially.

Re: Write code like a human will maintain it

#220

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 messages! And then I ask it, and it's like "oh, you're right, I have that instruction and I ignored it". If you were working with a junior developer, you'd expect at some point they get it, but with Claude even if I tell it to stuff the instructions into it's memory, it will do it, and STILL mess it up.

Then it gets even more fun, because if I politely correct it in the session, it will understand, but then there's a decent chance it will be completely unable to commit anything in the session going forward. Phd level intelligence!

Anyway, my point is, if you're asking it to review a list of 200 items I guarantee it's quietly messing up on a lot of that list.

Post reply on HN