Part of the issue will be the training and the reward function. It is difficult to reward for human readability, simplicity, etc.
You could use various tools and checks like:
- linters and other code style tools;
- line length;
- cyclometricity, etc.
- dead code checks (unused variables, etc.);
- lines of code/diff size.
Those don't check things like whether the code changes are minimal/don't make unrelated changes/etc.
There's also the issue of maintaining consistency. I.e. detecting the code style of the project/code and using that (quoting, etc.). You also find that in prose, such as with British vs American dialogue.
I think the only way to make the style consistent is to have some sort of "reasoning context" that can learn the overall style and apply/use that across all tokens. That way, the model wouldn't have to add it to the context, and it wouldn't suffer from things like the excluded middle and dropping out of the context.
Surprisingly, getting an LLM to write a custom linter that checks for a lot of common pitfalls based on string pattern search, paragraph length, sentence length, etc etc is actually quite effective as a way to force your LLM to behave.
It’s what I ended up doing, and it works pretty well.