How to effectively write quality code with AI

heidenstedt.org

151 points by i5heu 7 hours ago


ryanthedev - 6 minutes ago

I created my own Claude skill to enforce this and be sure it weaves in all the best practices we learned.

https://github.com/ryanthedev/code-foundations

I’m currently working on a checklist and profile based code review system.

hannofcart - an hour ago

The post touches very briefly on linting in 7. For me, setting up a large number of static code analysis checks has had the highest impact on code quality.

My hierarchy of static analysis looks like this (hierarchy below is Typescript focused but in principle translatable to other languages):

1. Typesafe compiler (tsc)

2. Basic lint rules (eslint)

3. Cyclomatic complexity rules (eslint, sonarjs)

4. Max line length enforcement (via eslint)

5. Max file length enforcement (via eslint)

6. Unused code/export analyser (knip)

7. Code duplication analyser (jscpd)

8. Modularisation enforcement (dependency-cruiser)

9. Custom script to ensure shared/util directories are not over stuffed (built this using dependency-cruiser as a library rather than an exec)

10. Security check (semgrep)

I stitch all the above in a single `pnpm check` command and defined an agent rule to run this before marking task as complete.

Finally, I make sure `pnpm check` is run as part of a pre-commit hook to make sure that the agent has indeed addressed all the issues.

This makes a dramatic improvement in code quality to the point where I'm able to jump in and manually modify the code easily when the LLM slot machine gets stuck every now and then.

(Edit: added mention of pre-commit hook which I missed mention of in initial comment)

OptionOfT - 5 hours ago

I wonder at the end of this if it's the still worth the risk?

A lot of how I form my thoughts is driven by writing code, and seeing it on screen, running into its limitations.

Maybe it's the kind of work I'm doing, or maybe I just suck, but the code to me is a forcing mechanism into ironing out the details, and I don't get that when I'm writing a specification.