Coding style guidelines for AI?

There seem to be a fair few of us using AI to work on this repo, and I remember that last time I did it, I had to go back and re-do a bunch of work because what it spat out did not fit the conventions of the repo.

I am now playing with some more modifications, so I thought I would have a stab at giving it some conventions up front, but not really knowing WTF I am talking about C/C++ wise (And it was too long ago that I did it that my memory is now hazy), I am not sure what it has written is good.

I am thinking that maybe we can come up with some prompts which cause it to generate code in an appropriate style in the first place, which we can all use, and commit it to the repo.

Does anyone fancy reviewing these files and seeing if they think it covers it?

I guess the place it has put it is probably specific to my AI agen (GitHub copilot), so it maybe needs moving somewhere else ultimately, and then each author would be responsible for pointing there AI at the relevant files

Tagging @marcmerlin on this one (Sorry for spamming you today mate!)

Its probably a good idea.
maybe putting AGENTS.md in the root of the project as thats what most environments recognise.

I’m not one to craft it though :),
But I imagine things like keep the same coding style, where you can keep things modularized, make sure comments are added to make it clear to anyone trying to maintain it in future etc

I obviously didn’t pick the C++ style since I didn’t author this project but what I would do, is:

  1. tell AI to analyse the C style and write a spec sheet for it

  2. save that spec sheet in a README in the project that other AIs can just read and apply as is

In my experience, GitHub CoPilot (aka Microsoft CoPilot) isn’t always delivering brilliant code.

I’ve had consistently good value from Claude - integrate github and Claude into Visual Studio and away you go!

Just check everything any AI produces.

I second that, the output I get from Claude is pretty good, specifically on Opus model with Extra effort. One thing which I’ve found invaluable and it’s not for everyone is to close the loop, so Claude Code has direct access not just to the target (Pi) but the output. Having Claude apply a shadow canvas layer on the panel output let me request key functionality and it will iterate until it’s solid.

While it can be a bit comment heavy, which isn’t a bad thing given it parses its own comments as expected in the absence of memory or an appropriate MD file, the results are reasonably good.

It’s pretty good at C and C++ output respecting formatting and structure, PHP and Java are pretty good too (you’d expect Java to be as good!), but it struggles with Delphi but it’s still not too bad.

Codex (ChatGPT) is also really good too, although I’ve had ChatGPT stumble over things (mainly around circuit diagnosis, trivial stuff) which Claude nailed first time, but everyone else’s mileage may vary. Not used Github Copilot, curious how it compares!

I know I found like a total Claude fanboy and I do apologise for that, but being a developer for the past 35 years in almost every language I could get my hands on like a lot of us here, I am genuinely starting to question the value in my coding anything, ever. I know that’s contraversial, and this is certainly my experience, but once I’d closed any loops as mentioned above, effectively going full skynet and letting it mark its own homework, the quality of what it has produced far exceeds anything I could do in the time frame.

Creative, explicit prompting is critical as @evilC has mentioned, the AGENTS.MD is a really good idea, and while my personal libraries might be an absolute unreadable, yet functional and solid mess, I’d imagine those guidelines would ensure a consistent output.

(sorry for the wall of text!)

Ross

2 Likes