Skip to main content

Chapter 2: Code Generation and Debugging

Code Generation Template​

Language: \{LANGUAGE\}
Framework: \{FRAMEWORK\} (if applicable)

Task: \{DESCRIPTION\}

Requirements:
- Input: \{INPUT_TYPES\}
- Output: \{OUTPUT_TYPE\}
- Edge cases: \{EDGE_CASES\}
- Performance: \{REQUIREMENTS\}

Include:
- Type hints/annotations
- Docstrings with examples
- Error handling
- Unit tests (optional)

Style: \{STYLE_GUIDE\}

Debugging Prompts​

Debug this \{LANGUAGE\} code:

```{language}
\{CODE\}

Error message: \{ERROR\} Expected behavior: {EXPECTED} Actual behavior: {ACTUAL}

Please:

  1. Identify the bug
  2. Explain why it occurs
  3. Provide the fixed code
  4. Suggest how to prevent similar bugs

## Code Review

```text
Review this code for:
- [ ] Correctness/bugs
- [ ] Performance issues
- [ ] Security vulnerabilities
- [ ] Code style/readability
- [ ] Best practices

Format:
| Line | Issue | Severity | Suggestion |
|------|-------|----------|------------|

Documentation Generation​

Generate documentation for this \{LANGUAGE\} \{TYPE\}:

```{language}
\{CODE\}

Include:

  • Description
  • Parameters (types, descriptions)
  • Return value
  • Usage examples (3)
  • Exceptions/errors

## Key Takeaways

:::tip[Summary]
1. Specify **language, framework, style guide**
2. Include **input/output types and edge cases**
3. Request **explanations** with code
4. Use **structured formats** for reviews
:::

---

**[← Previous: Content Creation](/module_07/chapitre1-content-creation)** | **[Next: Data Analysis β†’](/module_07/chapitre3-data-analysis)**