Effective Use of AI in COMP 477

In this course, you are encouraged to use AI tools to their fullest potential. However, "using AI" is not a substitute for understanding. The goal is to leverage these tools as a partner to enhance your learning, accelerate development, and deepen your insights into systems programming. This guide outlines several modalities of AI interaction and offers advice on using them effectively.

Modalities of AI-Assisted Coding

1. AI Chat (e.g., ChatGPT, Gemini)

This is the most common form of interaction. You engage in a dialogue with an AI, asking questions, providing code snippets, and iteratively refining a solution.

  • Pros: Excellent for brainstorming, debugging complex logical errors, exploring alternative implementations, and getting high-level architectural suggestions.
  • Cons: Can be slow due to context-switching. The AI lacks full project context, so you must provide all relevant code, which can be cumbersome and lead to inaccurate suggestions if incomplete.
Example Prompt: "I'm writing a function in Rust to parse a configuration file. The file can have key-value pairs. What's an idiomatic way to handle potential I/O errors and parsing errors, returning a single, helpful error type?"

2. IDE Code Completion (e.g., GitHub Copilot in VS Code)

This modality involves real-time, inline code suggestions directly in your editor as you type. The AI uses the content of your current file and open tabs as context.

  • Pros: Extremely fast for boilerplate code, implementing known patterns, and completing routine functions. It reduces typing and lookup time significantly.
  • Cons: The suggestions are often locally optimized and may not align with the broader project architecture. It can encourage a "tab-and-forget" mentality, where developers accept code without fully understanding it.

3. Agent in the IDE (e.g., Antigravity, Cursor)

This combines the chat modality with deep IDE integration. The agent has access to the entire project context and can perform actions like scaffolding code, adding tests, or refactoring across multiple files.

Even though it may seem like the agent knows what it is doing, thorough testing is still extremely important. You and the agent can and should collaborate to generate test cases that provide robust test coverage. Do not solely rely on the agent to generate correct code or appropriate tests.

  • Pros: Context-aware suggestions are far more accurate. Can help you understand unfamiliar codebases by tracing execution paths, explaining complex interactions, and identifying architectural patterns. Can automate complete feature development cycles including implementation, testing, and documentation.
  • Cons: Can be resource-intensive. You must still guide the agent with high-quality instructions and verify its work. This can be complicated by the fact that the agent may produce large amounts of code across the project that need to be carefully reviewed.

4. Agent in the CLI (e.g., GitHub Copilot CLI, Claude Code)

This modality treats the AI as a command-line tool. It operates on the filesystem, runs commands, and uses tools to accomplish goals. It's well-suited for tasks that involve not just code, but also build systems, configurations, and deployment.

Such command line agents are extremely useful for tasks such as installing an unfamiliar computing tool and environment. However, allowing the agent direct access to the command line necessitates close supervision since erroneous agent commands can have devastating consequences (e.g. erasing your entire filesystem). The true best practice is to confine these agents to a sandboxed environment (e.g., a container) where any damage would be limited.

  • Pros: The most powerful modality for comprehensive development work. Can handle complete feature lifecycles from initial design through testing and debugging. Excellent for learning, as it can analyze and explain existing code architecture while working. Its grounding in the actual project environment ensures solutions are practical and integrate well with the project as a whole.
  • Cons: Requires a different mindset; you describe the goal, and the agent determines the steps. It can be less interactive for fine-grained code changes. And again, you must still verify its work, which can be even more daunting, as the changes can now easily sprawl across your entire system.
Example Interaction: "Add a new API endpoint '/status' that returns the current version from the 'Cargo.toml' file and include comprehensive tests."

Recommendations for Effective AI Usage

Your ability to use these tools effectively is a skill in itself. For this course, remember that you are accountable for every line of code you submit, regardless of its origin.

  1. Lead with Agents: For any substantial work, start with an IDE or CLI agent. They provide the most comprehensive and contextually-aware assistance, handling everything from initial architecture to testing. This approach can be transformative for productivity and learning.
  2. Plan before Acting: Have the agent help you formulate a clear plan before diving into code generation. Make sure you carefully review and revise the plan with the agent until you are confident that the approach is sound. Keeping the end goal in mind and the agent on task throughout the process is critical for success.
  3. Leverage Agents for Learning: When encountering unfamiliar code or concepts, use agents to explain architectural decisions, trace execution flows, and understand design patterns.
  4. Use Chat for Focused Exploration: When you need to explore specific design trade-offs or debug particular issues, chat interfaces allow for deep, iterative discussion (e.g., "Should I use Arc<Mutex<T>> or channels for this concurrency problem? Why?").
  5. Supplement with Completion: Use inline completion to accelerate routine implementation tasks once your overall approach is established. Let it handle the boilerplate while you focus on the architecture.
  6. Always Verify: After accepting AI-generated code, pause and ask yourself: "Can I explain this to someone else?" If not, use an agent to walk through the code and explain its operation (though you must verify that the explanation is correct). If you are still unsure, you should probably pursue a different approach.
  7. Take Responsibility: You are responsible for your code, no matter how much, or how little, AI assistance you make use of. You must carefully review, test, and understand every line of code. Treat every AI suggestion as if it came from a new team member: it might be brilliant or it might be fatally flawed. Your job is to tell the difference.