Coding সহকারী — Generation, Debug, Refactor

লেসন ১৩ / ৪৬

💻 Code Generation Prompt ⭐

"Write a Python function that:
- Input: list of dicts with 'name' (str) and 'age' (int)
- Output: dict grouped by age range (0-17, 18-35, 36+)
- Use type hints
- Include docstring with example
- Handle empty input gracefully
- No external libraries"

📚 Context দিন

  • Language version (Python 3.12, ES2024)
  • Framework (FastAPI, Express)
  • Code style (PEP8, Airbnb)
  • Existing pattern (১টা sample paste)
  • Constraint (no jQuery, async only)

🐛 Debugging Prompt

"Here is code that throws TypeError on line 42.

[paste code]

Error:
[paste full traceback]

What I tried:
1. Print debug — value was None sometimes
2. Type check — int/None mix

Context: Async loop with 10K items.

Diagnose root cause and provide fix with explanation."

♻️ Refactor Prompt

"Refactor this function for:
1. Readability (clear names)
2. Performance (current O(n²) → target O(n log n))
3. Testability (pure function)
4. Modern syntax (async/await)

Show: original analysis → refactored code → benchmark"

🧪 Test Generation

"Write Jest unit tests for this function:
[code]

Cover:
- Happy path (3 cases)
- Edge cases (empty, null, max int)
- Error cases (invalid input)
- Async behavior
Use AAA pattern. Mock external deps."

👀 Code Review

"Review this PR diff:
[paste diff]

Check:
- Bugs / logic errors
- Security (SQL injection, XSS, secret)
- Performance issues
- Best practice violation
- Naming, readability
- Missing test
- Documentation gap

Format: file:line — issue — suggestion"

🏛️ Architecture Decision

"Compare 3 approaches for [problem]:
- Approach A: [...]
- Approach B: [...]
- Approach C: [...]

Table: criteria | A | B | C
Criteria: complexity, performance, cost, scalability,
          team familiarity

Final recommendation with reasoning."

📖 Documentation

"Generate docs for this module:
[code]

Output:
1. Module overview (2 paragraph)
2. API reference (each function: signature, params,
   returns, throws, example)
3. Usage tutorial (3 progressive examples)
4. Common pitfalls
Format: Markdown"

🤖 AI IDE Best Practice

Cursor / Windsurf

  • @file দিয়ে specific file reference
  • @docs দিয়ে library docs pull
  • Agent mode-এ multi-step task
  • Rules file (.cursorrules) দিয়ে project convention

GitHub Copilot

  • Comment-driven ("// function to..." লিখে wait)
  • Tab accept, Esc reject
  • Alt+] / Alt+[ alternatives দেখুন
  • Chat-এ detailed question

Claude Code / CLI agent

  • Agentic task-এ best
  • File modify, command run
  • Step-by-step plan দেখায়
  • Git-এর সাথে integrate

👥 Pair Programming Pattern

"You are my pair programmer. Rules:
- Push back on bad ideas
- Suggest tests as we go
- Catch obvious bugs
- Don't write code I haven't reviewed
- Ask before changing >10 lines

Let's start: I want to add caching to..."

📏 Working with Large Codebase

  • Cursor / Windsurf — full repo context
  • Claude Projects — codebase upload
  • Chat-এ শুধু relevant ১-৩ file
  • File tree আগে দিন
  • Pattern reference: "follow style of utils/helper.ts"

❌ Common Mistake

  • Password/key code-এ paste করা
  • Generated code না পড়ে use করা
  • Hallucinated package trust করা
  • Test skip ("AI লিখেছে, ঠিকই হবে")
  • বোঝা ছাড়া copy-paste
  • Blind trust on AI architecture decision

💪 Power User Tips ⭐

  • Complex task step-by-step — একসাথে ৫০০ line না
  • Successful prompt snippet হিসেবে save
  • Design-এ o1/Claude Opus, boilerplate-এ GPT-4o-mini
  • Iterate: code → test → refactor
  • সবসময় run + verify করুন
  • Code-এর সাথে explanation চান
  • "Teach me" mode — AI এর কাছ থেকে শিখুন

🎯 Workflow Example

1. Feature description (natural language)
2. AI → plan break down
3. Human review plan
4. AI → first file (skeleton)
5. Human test
6. AI → next file
7. Iterate
8. Human → final review + merge
9. AI → PR description + commit message