Session 2: (AI-Powered) Coding and Development
1 Introduction
This session focuses on how AI can enhance your coding and development workflow. We will investigate how to use integrated coding assistants to increase the speed of development.
2 Getting Started with GitHub Codespaces
We will be using GitHub Codespaces for this session. This provides a full development environment in your browser, pre-configured with all the necessary tools.
2.1 Understanding the VS Code Interface
When you open Codespaces, you will see Visual Studio Code (VS Code) running in your browser. It consists of several key areas:
- Activity Bar (Left Sidebar): Lets you switch between views like Explorer (files), Search, Source Control (Git), and Extensions.
- Side Bar (Next to Activity Bar): Shows the details of the current view (e.g., your file tree).
- Editor (Center): The main area where you edit your code. You can have multiple tabs open.
- Panel (Bottom): Displays the Terminal, Debug Console, Output, and Problems. This is where you’ll run commands and see program output.
- Status Bar (Bottom Edge): Shows information about the current project, git branch, and cursor position.
3 Exercise: Explore the Environment
Before we dive into coding, let’s get familiar with the environment.
- Open the Explorer: Click the top icon in the Activity Bar (or press
Ctrl+Shift+E/Cmd+Shift+E). Look at the file structure. - Open the Terminal: If not visible, press
Ctrl+`(backtick) or go to the menu Terminal > New Terminal. - Find the Extensions: Click the square icon in the Activity Bar. Search for “Python” to see that it is already installed.
- Locate the Command Palette: Press
Ctrl+Shift+P(orCmd+Shift+P). Type “Theme” and try changing the Color Theme.
3.1 The Myth vs. The Reality
The Myth: AI writes code for you while you sleep.
The Reality: AI acts as a very fast and enthusiastic Junior Developer. It understands syntax and grammar but lacks awareness of your intent unless explicitly instructed. Consequently, our roles pivot from simply writing code to reviewing and managing it. This is well enabled in GitHub using pull requests and code review (beyond the scope of this session).
3.2 The CIC Framework
CIC stands for Context, Instruction, Constraints. It is a useful framework for communicating with an AI developer, similar to the STAR framework used in interviews. Following this framework ensures your AI assistant understands both the requirements and your intent.
3.2.1 Examples
Bad Example: “Make me a graph of this data.”
Good Example: “I am analysing transport data for a government contract focusing on bus delays (Context). My data has columns named
delayandroute. Create a histogram of this data where the delay is subset by route (Instruction). Make the figure suitable for professional publication. Ensure that all errors are gracefully caught and resolved, and use PEP8 best practices throughout (Constraints).”
The good example typically yields high-quality, readable code, whereas the bad example produces unpredictable results.
3.3 Trust but Verify
Despite best efforts, errors may occur. In our role as reviewers and managers, we must be mindful of pitfalls and ensure code is tested and verified.
- Hallucinations: The model may generate plausible but meaningless strings of tokens, such as non-existent packages or inaccurate variable names.
- Verification: Never assume the first draft is perfect. Always run the code immediately to check for errors and use known test data to verify results align with expectations.
- Security: Never paste passwords, API keys, or private personal data into the chat. Unless told otherwise, always assume that your data will be used to train other models.
It is crucial to maintain “Human in the loop” workflows to prevent AI agents from running out of control. Version control systems like Git and collaboration platforms like GitHub enable the integration of AI input with quality assurance through Pull Requests (similar to tracked changes in Word), code reviews, and a human-led merge process. Additionally, safeguards such as maximum expenditure limits per day, project, or user can help mitigate risks.
3.4 Interacting With the AI Assistant
There are four primary ways to interact with an AI coding assistant:
- Copy / Paste: Asking questions via a web interface and pasting the response. Useful for single tasks but less integrated than modern IDE solutions.
- Auto-Complete: The assistant provides line-by-line completion suggestions as you type. You can accept suggestions with
TABor ignore them. - Code Inspection: Highlighting code to ask specific questions, such as debugging, reviewing, or optimizing. A recommended approach is asking the assistant to make code more professional and efficient, then reviewing the suggested edits.
- Vibe Coding: Designing a project specification with context and asking the agent to build it. The agent generates project files for your confirmation.
4 AI-Powered IDEs
- Introduction to AI Coding Assistants: We’ll look at GitHub Copilot as a future-proof example of an AI coding assistant embedded into existing tools.
- Live Demonstration
5 Exercise: Create a new figure using GitHub Copilot
- Task: Use Copilot to modify the
data/od_viewer.pyPython file to make a new plot of something that interests you.
6 Bonus Exercise: Interacting with GitHub to enable version-controlled collaborative workflows embedding AI
Note: this bonus exercise is designed for those already comfortable with GitHub and version control concepts, or those who are ahead of schedule and wish to explore further.
Task: Contribute to a shared repository using an AI-assisted workflow.
- Fork and Clone the exercise repository.
- Create an issue describing a new feature you will add.
- Create a branch linked to your issue.
- Use Copilot to write the code for the new feature.
- Commit and push your changes.
- Create a pull request for your work to be reviewed.
See the materials on the Data Science for Transport Planning course website for more details.