Skip to main content
Ganesh Joshi
Back to Blogs

When to use AI vs write it yourself

February 13, 20265 min read
AI & coding
Code editor or terminal on screen

AI can speed up a lot of coding work, but not every task is a good fit. Using AI where it shines and writing yourself where it does not keeps quality high and avoids subtle bugs. Here is a practical framework for deciding.

The core principle

Use AI for tasks where mistakes are easy to catch. Write yourself for tasks where mistakes are hard to find or have serious consequences.

This simple rule covers most decisions. Boilerplate has predictable structure; you can spot errors quickly. Security logic has subtle edge cases; a mistake might not be obvious until it is exploited.

When to use AI

1. Boilerplate and repetitive code

Form handlers, API route skeletons, CRUD operations, type definitions from JSON, and similar repetitive code are strong use cases. The structure is predictable and easy to verify.

Good AI tasks:

  • Creating a new React component with standard props
  • Writing API endpoint boilerplate
  • Converting JSON to TypeScript interfaces
  • Generating Prisma schema from requirements
  • Adding standard imports and exports

Generate a first draft, then adjust names, types, and edge cases to match your project. You save time without handing over critical logic.

2. Test scaffolds and outlines

AI can generate test file structure, mock setups, and test case outlines for existing functions. You fill in the specific assertions and edge cases.

Good AI tasks:

  • Creating test file boilerplate
  • Generating describe/it blocks for each function
  • Setting up mocks for dependencies
  • Writing basic happy-path tests

Review the generated tests and add cases the AI missed. Test coverage is better than no coverage, and AI helps you start faster.

3. Documentation drafts

README sections, JSDoc comments, API documentation, and inline comments can be drafted by AI. You edit for accuracy and tone.

Good AI tasks:

  • Generating function documentation from signatures
  • Drafting README installation and usage sections
  • Writing API endpoint descriptions
  • Adding comments to complex code

Always verify against the actual code. AI can describe what it thinks the code does, not what it actually does.

4. Explanations and learning

Ask AI to explain dense functions, unfamiliar patterns, or library usage. This is low-risk because you are learning, not shipping.

Good AI tasks:

  • Explaining what a regex does
  • Describing how a hook or pattern works
  • Comparing different approaches
  • Suggesting refactoring options

Use the explanation as a starting point. Verify against documentation or testing.

5. Exploration and prototyping

Use AI to explore approaches quickly. Ask for multiple solutions, compare them, then implement your chosen approach properly.

Good AI tasks:

  • "Show three ways to implement caching here"
  • "What are the trade-offs between these state management options?"
  • "Generate a quick prototype of this feature"

Exploration is low risk. The final implementation should be something you understand and can maintain.

When to write it yourself

1. Security-sensitive code

Authentication, authorization, input validation, encryption, and anything that touches secrets or user data should be written or carefully reviewed by you.

Write yourself:

  • Login and session management
  • Permission checks and access control
  • Input sanitization and validation
  • Password hashing and token generation
  • Payment processing logic

AI can hallucinate secure patterns or miss edge cases. Use AI for surrounding glue code if you like, but the security-critical paths must be under your control and reviewed line by line.

2. Core business logic

Algorithms, pricing rules, compliance logic, and domain-heavy code often have subtle requirements that are hard to put in a prompt. A wrong assumption can cause hard-to-find bugs.

Write yourself:

  • Pricing and discount calculations
  • Tax and compliance rules
  • Domain-specific algorithms
  • State machines with complex transitions
  • Anything with regulatory requirements

For this kind of logic, write it yourself or use AI only to generate a rough sketch and then rewrite with your understanding.

3. Performance-critical code

Code that runs in hot paths, handles large data, or has strict performance requirements needs careful optimization that AI often cannot provide.

Write yourself:

  • Database query optimization
  • Memory-intensive operations
  • Real-time processing logic
  • Caching strategies with invalidation

AI can suggest naive implementations that work but do not scale. Profile and optimize yourself.

4. Integration with legacy or complex systems

When integrating with legacy systems, undocumented APIs, or complex internal tools, AI often lacks the context to be helpful.

Write yourself:

  • Legacy system integrations
  • Undocumented internal API calls
  • Complex migration scripts
  • System-specific workarounds

You need to understand the quirks and edge cases that are not in any prompt.

Decision framework

Use this table to decide quickly:

Task type Use AI? Why
Boilerplate (forms, routes, types) Yes Predictable structure, easy to verify
Test scaffolds Yes Get started faster, fill in details yourself
Documentation drafts Yes Edit for accuracy, saves time
Explanations and learning Yes Low risk, helps understanding
Exploration and prototypes Yes Compare approaches, implement yourself
Authentication and authorization No Security-critical, subtle edge cases
Core business logic No Domain knowledge required, bugs are costly
Performance-critical code No Needs profiling and optimization expertise
Legacy/undocumented integrations No Context AI does not have

How to stay in control

Even when using AI, maintain ownership:

  1. Understand what you ship. Do not merge code you cannot explain.
  2. Review everything. Treat AI output as a draft from a junior developer.
  3. Test thoroughly. AI mistakes often hide in edge cases.
  4. Refactor to your standards. AI code may not match your patterns.
  5. Document your decisions. Your future self needs to know why, not just what.

The hybrid approach

The best workflow combines AI speed with human judgment:

  1. Use AI to generate a first draft of boilerplate, tests, or documentation.
  2. Review and edit for correctness, style, and edge cases.
  3. Write security and core logic yourself, perhaps using AI for surrounding code.
  4. Test everything, whether AI-generated or hand-written.
  5. Iterate with AI help for refactoring and improvement.

This gives you the productivity benefits of AI without the risks of blind trust.

Summary

Use AI for tasks where mistakes are easy to catch: boilerplate, tests, docs, and exploration. Write yourself for tasks where mistakes are costly: security, core business logic, and performance-critical code.

For a checklist on reviewing AI output before it goes in, see Reviewing AI-generated code. For more practical habits, see AI-assisted coding: practical tips.

Frequently Asked Questions

Use AI for boilerplate code, repetitive tasks, test scaffolds, documentation drafts, and code explanations. These are low-risk tasks where AI saves time and mistakes are easy to catch.

Write security-sensitive code, authentication, authorization, core business logic, and domain-specific algorithms yourself. These require deep understanding and careful review that AI cannot provide.

AI can suggest code that looks secure but has subtle vulnerabilities. For security-critical paths, write the code yourself or review AI output line by line. Never trust AI blindly for auth, permissions, or input validation.

Yes. AI is great for exploration. Ask for multiple approaches, understand the trade-offs, then implement the chosen approach yourself. Use AI to learn, not to avoid understanding.

Ask: Is the task repetitive or boilerplate? Is the structure predictable? Are mistakes easy to catch? If yes, use AI. If the task involves security, compliance, or subtle domain logic, write it yourself.

Related Posts