Key Points

Introduction to AI-assisted Coding


  • AI coding tools range from autocomplete to highly autonomous development.
  • Higher AI autonomy requires greater human oversight and review.
  • Established software engineering practices remain essential when using AI.
  • AI can speed up development, learning, prototyping, and documentation.
  • AI-generated code may be incorrect, insecure, or poorly designed.
  • Developers remain responsible for validating all AI outputs.
  • Over-reliance on AI can increase technical debt and reduce understanding.
  • “Almost right” AI solutions often increase debugging and maintenance effort.
  • AI tools are evolving rapidly, and best practices are still emerging.
  • The Copilot free tier currently includes access to three AI models each with a different balance of speed and purpose.
  • The Copilot free tier currently allows 2000 completions and 50 premium requests per month.

Example Code


  • The example Python code generates a basic set of statistical plots for all data files within the data/ directory.
  • The code has a number of deliberate issues that we want to resolve throughout this lesson using GitHub Copilot.

Getting Started with GitHub Copilot


  • Configure Copilot privacy settings to disable public code suggestions and data-sharing before use.
  • Use Ask mode to explore and understand an unfamiliar codebase without making changes.
  • Copilot responses are probabilistic and non-deterministic, with the same question yielding different answers.
  • Write specific, concise prompts and break complex questions into separate steps for better results.
  • Use # to add explicit context (such as files or folders) to chat prompts.
  • A .github/copilot-instructions.md file provides persistent project-level guidance to Copilot for things like coding style and conventions.
  • Always critically evaluate AI-generated explanations and code, since they can be confidently incorrect.
  • Monitor your Copilot quota, especially when using higher-cost models (marked with multipliers greater than 1x).

Refactoring Code with GitHub Copilot


  • Copilot offers three levels of refactoring support: inline suggestions, agent mode, and plan mode, in ascending order of autonomy and scope.
  • Inline suggestions appear as ghosted text while typing and are driven by immediate code context.
  • Agent mode can make targeted edits across multiple lines or functions when given a specific instruction.
  • Plan mode analyses the codebase and produces a step-by-step refactoring plan without making any changes, enabling review before implementation.
  • AI-generated suggestions should always be reviewed and understood before accepting; increasing autonomy requires increasing scrutiny.