Best Practices for AI Coding
Guiding AI for Optimal Results
Define Architecture First: Decide on your framework, folder structure, data models, and authentication before prompting AI, as AI excels at implementation but is less effective at judgment. "AI tools are perfect at implementing and executing. But it's mid at judgement. Pick your framework, folder structure, data models, auth before prompting."
Provide Persistent Context: Use rules files to define your tech stack, project concept, and things to avoid to keep the AI aligned. "Always give persistent context. Use rules files with your tech stack, project concept, things to avoid, and so on. basically have your rules and project explained in rules files"
Break Down Complex Tasks: Avoid sending multiple prompts for huge changes, as AI memory can degrade quality for later prompts; send them one by one. "Dont give a series of prompts when you make huge changes. AI has memory, and if u send all 10 prompts of different things, first two will be done fine, other 8 with be bad quality. Send one by one, that way u maximize the quality of results"
Ensuring Code Quality and Reliability
Commit Frequently: Commit before every meaningful change, as version control systems like Git provide reliable ways to revert AI-generated mistakes. "Always commit. Commit before every meaningful change. git has a quick command that guarantees to undo changes, while AI can mess up with reverting"
Test Everything Thoroughly: Even when AI verifies code, always act as a real user to test and click through all features, and report any errors back to the AI. "Test the website's features every single time. Even if you ask AI to verify the code it still can mess up. be a real user that tests and clicks around everything. show AI all errors you faced."
Maintain a Strong Test Suite: Invest heavily in your test suite early, as AI is good at generating code but less so at verifying correctness, making a solid test framework crucial for catching regressions. "invest heavily in your test suite early. the AI is incredible at generating code but mediocre at verifying correctness."
Managing AI-Generated Code
Understand AI Limitations: Recognize that AI is a language model that doesn't truly understand the higher-level function of your application, and may generate spaghetti code or non-performant solutions. "Remember, AI is just a language model. It doesn't really understand at a higher level what the function of your application is and how it's supposed to work."
Review All AI Output: Do not lazily copy and paste AI output; take time to understand what you're asking and how the output fits into your project, asking the AI for explanations and references as needed. "Take your time to understand explicitly what you’re asking and how the output fits into a larger project."
Treat the Codebase as the Source of Truth: Instead of relying on chat memory, make the codebase and documentation files (like CLAUDE.md or AGENTS.md) the persistent layer for context and decisions. "the fix is making the codebase plus a checked-in instructions file (CLAUDE.md, AGENTS.md) the source of truth, not the chat."
Are you looking for more specific best practices related to particular AI coding tools or languages?
Bottom line
Leverage AI for coding by clearly defining your architecture, providing persistent context, and rigorously testing outputs, treating AI as an assistant rather than a replacement for human judgment.
Comments (0)
No comments yet. Start the conversation.