Skip to main content

Chapter 3: Best Practices and Limitations

Using AI Code Responsibly​

AI code generation is powerful but requires responsible use. Understanding limitations and best practices ensures quality and security.


When to Trust AI Code​

Higher Confidence ✅​

  • Common patterns (CRUD operations)
  • Well-documented libraries
  • Standard algorithms
  • Boilerplate code
  • Simple utility functions

Lower Confidence ⚠️​

  • Security-critical code
  • Complex business logic
  • Concurrency/threading
  • Edge cases
  • Performance-critical sections

Security Concerns​

Common Issues​

Examples to Watch For​

SQL Injection Risk:

# AI might generate:
query = f"SELECT * FROM users WHERE id = {user_id}" # UNSAFE!

# Should be:
query = "SELECT * FROM users WHERE id = %s" # Parameterized
cursor.execute(query, (user_id,))

Hardcoded Secrets:

# AI might include:
api_key = "sk-abc123..." # NEVER commit secrets!

Security Best Practices​

  1. Review all security-related code
  2. Never commit secrets
  3. Run security linters
  4. Test edge cases manually
  5. Use security scanning tools

Code Review Importance​

Always Review AI Code For:​

  • Logic errors
  • Edge cases
  • Security vulnerabilities
  • Performance issues
  • Code style consistency
  • Test coverage

Review Process​


Licensing and Attribution​

Potential Issues​

  • AI may reproduce training code
  • License compatibility concerns
  • Attribution requirements

Best Practices​

  • Don't use for copyrighted code
  • Check unique/critical functions
  • Document AI assistance if required
  • Follow company policies

Limitations​

What AI Code Generation Can't Do Well​

LimitationExample
Novel algorithmsNew research implementations
Domain expertiseIndustry-specific rules
Perfect optimizationPerformance-critical paths
Understanding intentAmbiguous requirements
Maintaining stateComplex stateful systems

Signs AI Code Needs Work​

  • Overly complex solutions
  • Unnecessary dependencies
  • Copy-paste patterns
  • Missing error handling
  • Inconsistent naming

Productivity Balance​

AI Enhances:​

  • Speed of initial implementation
  • Boilerplate reduction
  • Learning new technologies
  • Exploring solutions

Human Essential For:​

  • Architecture decisions
  • Code review
  • Security verification
  • Performance tuning
  • Domain logic

Team Guidelines​

  1. Disclosure: Note significant AI assistance
  2. Review Requirements: All AI code must be reviewed
  3. Security Rules: No AI for auth/crypto without expert review
  4. Testing Standards: AI code needs tests
  5. Training: Team knows limitations

Avoiding Over-Reliance​

Healthy Habits​

  • Understand generated code fully
  • Write critical code yourself
  • Use AI for learning, not avoiding learning
  • Regular coding without AI
  • Stay current with fundamentals

Warning Signs​

  • Can't code without AI
  • Accepting without understanding
  • Skipping reviews "because AI wrote it"
  • No longer learning fundamentals

Key Takeaways​

✅ Always review AI-generated code

✅ Security code requires extra scrutiny

✅ AI excels at common patterns, struggles with edge cases

✅ Human judgment remains essential

✅ Maintain coding skills independent of AI

✅ Establish team guidelines for AI use


Module Summary​

You've completed Module 7. You understand:

  1. Major Tools: Copilot, Cursor, Codeium, others
  2. Effective Use: Completion, generation, debugging
  3. Responsible Use: Security, review, limitations

Next Steps​

Take the Module 7 Quiz, then continue to Module 8: Multimodal AI.