IS4010: AI-Enhanced Application Development

Week 2: AI Tools for Programming - Interactive Companion Notebook

Instructor: Brandon M. Greenwell
Course: IS4010: AI-Enhanced Application Development
Week: 2 - AI Tools for Programming


🎯 Learning Objectives

By the end of this interactive session, you will be able to:

  • Understand the landscape of AI programming tools and their different use cases
  • Work with AI as a pair programming partner using the augment-not-automate philosophy
  • Craft effective prompts using the Context-Persona-Task-Format (CPTF) framework
  • Compare conversational AI models (Gemini, ChatGPT, Claude) for programming tasks
  • Use GitHub Copilot for inline code suggestions and conversational assistance
  • Apply prompt engineering techniques to debug, refactor, and document code
  • Write NumPy-style docstrings to communicate intent to AI assistants

🛠️ Prerequisites

  • Python 3.10+ installed
  • Access to a conversational AI tool (Gemini, ChatGPT, or Claude)
  • GitHub Copilot extension for VS Code (free for students)
  • Basic understanding of Python variables and functions

🔗 Resources


Session 1: Introduction to AI-Assisted Development

The AI Revolution in Programming 🚀

AI tools are transforming how we write code, but the key is understanding how to use them effectively. In this session, you’ll learn to work with AI as your pair programming partner, not your autopilot.

The Course Motto: Augment, Don’t Automate!

Think of AI as your co-pilot, not your autopilot: - AI provides suggestions → You review and approve - AI explains possibilities → You make decisions - AI generates code → You understand and own it - You remain responsible for all code you submit

Remember: The pilot is always responsible for the flight!

Understanding Large Language Models (LLMs) 🧠

Before we dive into using AI tools, let’s understand what they are:

  • Large Language Models (LLMs): AI systems trained on massive amounts of text from the internet
  • Pattern recognition experts: They’ve learned patterns in human language and code
  • Sophisticated autocomplete: Like your phone’s predictive text, but incredibly advanced
  • Not databases: They predict what text should come next based on patterns
  • Good at code: Programming languages follow patterns, just like natural language

Key Insight

LLMs were trained on billions of lines of code from GitHub and other sources. They learned that certain patterns appear together (like function definitions followed by return statements). This makes them surprisingly good at code completion, but they still require human judgment and verification.

Four Main Categories of AI Tools 🛠️

AI programming tools fall into four main categories:

  1. Conversational AI models: General-purpose models (Gemini, ChatGPT, Claude)
  2. Specialized code assistants: Purpose-built for coding (GitHub Copilot, Claude Code)
  3. Command-line tools: Terminal-based AI access (Gemini CLI)
  4. Code analysis tools: Project-wide review and feedback (Google Jules)

Each has unique strengths. Let’s explore when and how to use each one.

Session 2: Conversational AI Models

The Big Three: Gemini, ChatGPT, and Claude 🤖

These general-purpose AI models can help with programming tasks:

  • All offer free tiers - No cost barrier to entry
  • Strong programming support - Excellent for Python, explanations, and debugging
  • Different personalities - Each has unique strengths
  • Web-based interfaces - Easy to access from any browser
  • Great for learning - Perfect for explanations and code review

When to Use Conversational AI

  • Explaining code: “What does this function do?”
  • Debugging help: “Why am I getting this error?”
  • Architecture advice: “Should I use a list or dictionary here?”
  • Learning: “Explain list comprehensions in simple terms”
  • Code review: “What improvements could be made to this function?”

The CPTF Prompt Engineering Framework 📝

The quality of AI responses depends on the quality of your prompts. Use the CPTF framework:

Context

Provide the situation and relevant information

Persona

Tell the AI who to act as (e.g., “Act as a senior Python developer”)

Task

Be specific about what you want the AI to do

Format

Specify how you want the response structured

Example: Bad Prompt vs Good Prompt

Bad: “Fix my code”

Good:

Context: I'm writing a Python function to calculate student grades.
Persona: Act as a senior Python developer reviewing my code.
Task: Here's my function [paste code]. Find any potential bugs and suggest improvements.
Format: Provide your answer as a numbered list with explanations and corrected code.

🎯 Your Turn: Craft a CPTF Prompt

Let’s practice crafting a prompt using the CPTF framework. You’ll use this for Lab 02 Part 2.

Scenario: You have a buggy function that’s supposed to calculate the sum of even numbers in a list.

Your Task: 1. Read the buggy code below 2. Craft a prompt using the CPTF framework 3. Test your prompt with a conversational AI model 4. Document the results

# Buggy code - can you spot the error?
def sum_of_evens(numbers):
    """Calculates the sum of all even numbers in a list."""
    total = 0
    for num in numbers:
        if num % 2 == 1:  # This line has a bug!
            total += num
    return total

# Test the buggy function
test_numbers = [1, 2, 3, 4, 5, 6]
result = sum_of_evens(test_numbers)
print(f"Sum of evens in {test_numbers}: {result}")
print(f"Expected: {2 + 4 + 6} = 12")
print(f"Actual: {result}")

✍️ Exercise: Your CPTF Prompt

Double-click this cell to edit and write your prompt:

Context: [Describe what the code is supposed to do and what problem you’re facing]

Persona: [Who should the AI act as?]

Task: [What specific help do you need?]

Format: [How should the response be structured?]


AI Response Summary: [After testing your prompt, summarize what the AI said and whether it was helpful]

Five Essential Prompt Patterns 📋

Here are five prompt patterns you’ll use frequently:

1. Explain This Code

“Explain this Python dictionary comprehension step by step: {word: len(word) for word in text.split() if len(word) > 3}

2. Generate Boilerplate

“Write a NumPy-style docstring for a function that calculates the area of a circle given its radius.”

3. Refactor for Clarity

“Convert this for loop into a more Pythonic equivalent using list comprehension or built-in functions.”

4. Debug Assistance

“I’m getting a ‘TypeError: unsupported operand type(s)’ on line 15. Here’s my code… What’s the likely cause and how do I fix it?”

5. Architecture Advice

“I need to store student information (name, ID, grades). Should I use a list of dictionaries or create a Student class? Explain the pros and cons of each approach.”

🎯 Your Turn: Practice Prompt Patterns

Try each of the five prompt patterns with a conversational AI model:

  1. Pick ONE pattern from above
  2. Use it with your preferred AI (Gemini, ChatGPT, or Claude)
  3. Document the result in the cell below

Which pattern did you try? [Write your answer here]

What was the AI’s response? [Summarize the response here]

How helpful was it on a scale of 1-5? [Your rating and why]

NumPy-Style Docstrings: Communicating with AI 📝

A docstring is a string literal (enclosed in triple quotes """) that occurs as the first statement in a module, function, class, or method. Its purpose is to explain what the code does.

Why Docstrings Matter for AI

  • Clear communication: Good docstrings lead to good AI-generated code
  • Intent specification: Tell the AI what you want the function to do
  • Type information: Specify parameter and return types
  • Examples: Show the AI what correct usage looks like

NumPy Docstring Format

We use the NumPy style for its clarity and readability:

def calculate_area(length, width):
    """
    Calculate the area of a rectangle.

    Parameters
    ----------
    length : float
        The length of the rectangle in meters.
    width : float
        The width of the rectangle in meters.

    Returns
    -------
    float
        The area of the rectangle in square meters.

    Examples
    --------
    >>> calculate_area(5, 3)
    15.0
    
    >>> calculate_area(10, 2.5)
    25.0
    """
    return length * width

# Test the function
print(calculate_area(5, 3))
print(calculate_area(10, 2.5))

Docstring Structure Breakdown

  1. Brief description: One-line summary of what the function does
  2. Parameters section: Lists all parameters with types and descriptions
  3. Returns section: Describes the return value type and meaning
  4. Examples section (optional but recommended): Shows usage examples

Why This Style Works Well with AI

  • Structured format: AI tools recognize and understand this pattern
  • Type hints: Helps AI generate type-appropriate code
  • Clear intent: Detailed descriptions guide code generation
  • Examples: Show AI exactly what correct behavior looks like

🎯 Your Turn: Write a NumPy-Style Docstring

Practice writing a professional docstring for this function:

def calculate_grade(score, total_points):
    # TODO: Add a complete NumPy-style docstring above this comment
    # Include: description, parameters, returns, and at least one example
    
    percentage = (score / total_points) * 100
    
    if percentage >= 90:
        return 'A'
    elif percentage >= 80:
        return 'B'
    elif percentage >= 70:
        return 'C'
    elif percentage >= 60:
        return 'D'
    else:
        return 'F'

# Test your documentation
print(calculate_grade(85, 100))
print(calculate_grade(72, 80))

Session 3: GitHub Copilot - Your AI Pair Programmer

What is GitHub Copilot? 💻

GitHub Copilot is a purpose-built AI code assistant that integrates directly into VS Code:

  • Trained specifically on code: Billions of lines from GitHub repositories
  • Two main modes: Inline suggestions and Copilot Chat
  • Context-aware: Sees your current file, open files, and project structure
  • Real-time assistance: Get help as you type
  • Professional workflow: Stay in your editor, maintain flow state

Two Ways to Use Copilot

  1. Inline Suggestions: Ghost text appears as you type (press Tab to accept)
  2. Copilot Chat: Conversational interface within VS Code

Inline Suggestions: The Magic of Ghost Text ✨

How it works: 1. Write a descriptive comment or docstring 2. Start typing your function definition 3. Copilot suggests code in gray “ghost text” 4. Press Tab to accept, Esc to reject 5. Use Alt + ] (Windows) or Option + ] (Mac) to see alternative suggestions

Best Practices for Inline Suggestions

  • Clear comments: # Calculate the factorial of a positive integer
  • Descriptive names: calculate_factorial not calc_fact
  • Type hints: def factorial(n: int) -> int:
  • Good docstrings: Detailed NumPy-style documentation

Example: GitHub Copilot Workflow

Here’s what a typical Copilot workflow looks like. In VS Code, you would:

  1. Write the docstring (communicates intent to Copilot)
  2. Start the function definition
  3. Copilot suggests the implementation
  4. Review and accept (or modify) the suggestion

Example Function Stub (For Lab 02)

def factorial(n):
    """Calculate the factorial of a non-negative integer.

    Parameters
    ----------
    n : int
        The non-negative integer to calculate the factorial of.

    Returns
    -------
    int
        The factorial of n. Returns 1 for n = 0.
        
    Examples
    --------
    >>> factorial(5)
    120
    
    >>> factorial(0)
    1
    """
    # When you place your cursor here in VS Code and wait,
    # Copilot will suggest an implementation based on the docstring!
    
    # For this notebook, here's a manual implementation:
    if n == 0:
        return 1
    result = 1
    for i in range(1, n + 1):
        result *= i
    return result

# Test the function
print(f"factorial(5) = {factorial(5)}")
print(f"factorial(0) = {factorial(0)}")
print(f"factorial(7) = {factorial(7)}")

Copilot Chat: Conversational Help in Your Editor 💬

Copilot Chat provides three powerful modes:

1. Planning Mode

For architectural decisions and project structure: - “How should I structure a student gradebook application?” - “What’s the best way to organize this code into functions?”

2. Ask Mode

For questions, explanations, and debugging: - “Explain this regex pattern” - “Why am I getting this error?” - “What does this function do?”

3. Agent Mode

For autonomous task completion: - “Refactor this class to use data classes” - “Add error handling to all functions” - “Generate tests for this module”

Special Copilot Chat Commands

  • /explain - Explain selected code
  • /fix - Suggest fixes for problems
  • /tests - Generate unit tests
  • /doc - Add documentation

🎯 Your Turn: Plan Your Lab 02 Approach

Think about how you’ll use AI tools for Lab 02:

Part 1 (Copilot Driving School): - Write detailed docstrings for each function stub - Let Copilot suggest implementations - Review and test each suggestion - Accept, modify, or reject based on your understanding

Part 2 (Prompt Engineering Challenge): - Use CPTF framework for each problem - Test prompts with conversational AI (Gemini, ChatGPT, or Claude) - Document your prompts and AI responses in lab02_prompts.md - Understand the AI’s solutions before using them

Planning Exercise

Write down your strategy:

Which AI tool will you use for Part 2? [Your answer here]

How will you ensure you understand the AI-generated code? [Your approach here]

What will you do if Copilot’s suggestion doesn’t work? [Your strategy here]

Session 4: Command-Line Tools and Code Analysis

Gemini CLI: AI in Your Terminal 🖥️

The Gemini CLI brings AI assistance directly to your command line:

Why Use Terminal-Based AI?

  • Stay in your workflow: No switching between terminal and browser
  • Quick queries: Fast answers without leaving the command line
  • Scriptable: Can be integrated into automated workflows
  • Code context: Easy to pipe file contents directly to AI

Common Usage Patterns

# Start interactive session
gemini

# Quick question
gemini "How do I install pytest in Python?"

# Code generation
gemini "Write a Python function to read a CSV file"

# Debugging help
gemini "Explain this error: ImportError: No module named 'requests'"

# Code review
cat script.py | gemini "Review this code for bugs"

When to Use Gemini CLI

  • Quick package help: “How do I install X?”
  • Error explanations: “What does this error mean?”
  • Command examples: “Show me how to use git stash”
  • Code snippets: “Generate a function to do X”

Google Jules: AI-Powered Code Review 🔍

Google Jules represents a new category of AI tools that understand entire codebases:

Revolutionary Capabilities

  • Understands entire codebases, not just individual files
  • Comprehensive analysis: Security, performance, maintainability
  • Context-aware suggestions: Considers your project’s architecture
  • Educational feedback: Explains why changes are recommended

When to Use Jules

  • Before submitting labs: Get AI feedback on your complete solution
  • Code review: Identify issues across multiple files
  • Learning: Understand best practices in real projects
  • Refactoring: Find improvement opportunities
  • Addressing pull requests: Get help with PR feedback

Example Use Case

Before submitting Lab 02: 1. Upload your lab02/ folder to Jules 2. Get comprehensive feedback on all three functions 3. Review suggestions for improvements 4. Make informed decisions about changes 5. Submit with confidence

Your Professional AI Toolkit 🧰

Required for This Course (Free)

  • GitHub Copilot - Integrated code assistance in VS Code
  • Gemini CLI - Terminal-based AI for quick queries

Optional (But Worth Exploring)

  • ChatGPT - Alternative conversational AI
  • Claude - Another excellent conversational AI
  • Claude Code - Premium CLI tool (paid subscription)

Your Professional AI Workflow 🔄

Here’s a recommended workflow for AI-assisted development:

Daily Development

  1. Start with comments: Describe your intent clearly
  2. Use Copilot inline: Accept, modify, or reject suggestions
  3. Chat for complex problems: Switch to conversational help when stuck
  4. Command-line for quick help: Terminal queries for efficiency

Code Review and Submission

  1. Jules analysis: Upload complete projects for review
  2. AI-assisted debugging: Use chat to identify and fix issues
  3. Documentation: Generate docstrings with AI help
  4. Testing: Auto-generate test cases with /tests command

The Golden Rule

Never submit code you don’t understand!

  • AI provides suggestions → You make decisions
  • AI explains possibilities → You choose the best approach
  • AI generates code → You understand and verify it
  • AI finds patterns → You apply domain knowledge
  • You remain responsible for the final product

Ethics and Limitations ⚠️

AI tools are powerful but require human oversight:

AI Can Hallucinate

  • Models sometimes generate plausible-looking but incorrect code
  • Advice may sound authoritative but be outdated or wrong
  • Subtle logical errors may not be immediately obvious

You Own the Code

  • Never submit code you don’t understand
  • Test all AI-generated code thoroughly
  • Take responsibility for all submissions

Privacy Matters

  • Be cautious about sharing sensitive information
  • Don’t paste real passwords, API keys, or personal data
  • Use example data for prompts when possible

Academic Integrity

  • Document your AI usage in assignments
  • Understand the code you submit
  • AI should accelerate learning, not replace it
  • Follow course policies on AI assistance

🎯 Putting It All Together: Lab 02 Integration

You’ve learned the essential AI tools and techniques. Now apply them in Lab 02!

Lab 02 Success Strategy

Part 1: Copilot Driving School

  1. Write clear docstrings - Use NumPy format with detailed descriptions
  2. Let Copilot suggest - Place cursor in function body and wait
  3. Review carefully - Understand what Copilot suggests
  4. Test thoroughly - Verify functions work correctly
  5. Modify if needed - Don’t blindly accept suggestions

Part 2: Prompt Engineering Challenge

  1. Use CPTF framework - Context, Persona, Task, Format
  2. Be specific - Clear prompts get better responses
  3. Document everything - Save prompts and responses in lab02_prompts.md
  4. Understand solutions - Don’t copy-paste without understanding
  5. Iterate if needed - Refine prompts for better results

Your AI Assistant Checklist

Before starting Lab 02, make sure you have:

Remember: You Are the Pilot ✈️

  • AI provides suggestions → You make decisions
  • AI explains possibilities → You choose the best approach
  • AI generates code → You understand and verify it
  • Always maintain responsibility for your work

Good luck with Lab 02! Use AI wisely, learn actively, and code confidently!