Skip to main content
This lesson covers comment-driven development: writing descriptive comments or prompts that an AI assistant (for example, GitHub Copilot) can use to generate boilerplate code, helper functions, and tests. This workflow speeds up repetitive tasks—creating classes, validation logic, data-processing helpers, and test scaffolding—but always review and test generated code before using it in production.
A presentation slide reading "Comment-driven development" on the left and a blue "Demo" label on a dark curved shape on the right. A small "© Copyright KodeKloud" note appears in the bottom-left.
Below are cleaned-up, corrected examples that illustrate how comment-driven generation might produce workable code. The examples include:
  • A simple Employee class with type hints and validation
  • A data-processing method (process_stock_data) that operates on a pandas DataFrame
  • A module-level validation utility (validate_trading_parameters)
  • Pytest-based tests for the processing function and the validator
Be mindful: AI-generated scaffolding is a starting point. Validate, refactor, and add tests for edge cases before relying on generated code.
Use comment-driven generation to create boilerplate quickly, then inspect and refine the generated code. Never blindly accept generated code without understanding it.

What you’ll find in this example

main.py

This module provides a minimal, well-typed implementation that includes:
  • An Employee class with validated attributes (name, age, salary)
  • process_stock_data method that:
    • Calculates 50-day and 200-day simple moving averages (SMA_50, SMA_200)
    • Computes daily returns and 50-day rolling volatility
    • Produces simple trading signals: 1 (bullish), -1 (bearish), 0 (neutral)
  • A validate_trading_parameters helper to assert basic order parameters
  • A small demo guarded by if __name__ == "__main__" to show usage
Example console output when running the module:

test_main.py

This lightweight pytest module demonstrates how to test the validator and the processing function. The tests focus on expected behavior and error handling rather than asserting precise numeric values for large rolling windows (50, 200) when using very small datasets.
AI-generated code can be helpful for scaffolding, but it may miss domain-specific edge cases. Always write unit tests, review type safety, and validate behavior on realistic datasets before deploying.

How to use this workflow

  • Write clear, intent-revealing comments that describe function inputs, outputs, and edge cases you care about.
  • Use comment-driven generation to quickly scaffold classes, functions, and tests.
  • Manually review generated code for correctness, style, and security issues.
  • Extend the generated tests to cover boundary conditions, error paths, and performance characteristics.
  • Iterate: refine prompts and regenerate when scaffolding doesn’t meet requirements.
This approach is best for repetitive patterns and boilerplate. It accelerates development but does not replace careful review and testing. In a follow-up article, we’ll build a fake data generator project to create synthetic datasets for more extensive testing and prototyping.

Watch Video