Guides for SE student projects »

This is a WIP community resource, containing contribution from community members.

AI-Assisted Coding

A: Tools and Resources

Resources we have created to help with the AI-assisted coding are given below:

B: Ideas for Using AI Tools in Coding

B1: Asking an LLM

AI tools such as large language models (LLMs) can act as conversational partners for coding tasks. You can ask them questions, provide code snippets, and request feedback or improvements.

Examples: Ask an LLM such as ChatGPT,

  • Here is a piece of code that I wrote. How can I improve it?
  • Take this code and tweak it so that the output is sorted alphabetically.
  • Here is an error message. What does it mean? How should I fix it?
  • This method is supposed to sort the output in ascending order but the actual output is in descending order. Why? How do I fix it?

B2: Use IDE-Integrations as an Auto-Completion Tool

AI Tools that has IDE integrations can work as an 'auto-complete on steroids', suggesting snippets of code that you can insert at the current cursor position. Some can go further in this direction.

Examples:

  • when you write a header comment for a method, the tool generates the method
  • write header comments for a method you have implemented
  • generate test cases for a method/class

Example: GitHub Copilot plugins for Intellij and VSCode

B3: Collaborate with an AI Coding Agent

It is possible to make your codebase visible to an Agentic AI tool, and get it to act like a team member who performs coding tasks.

Examples:

B4: Generate Whole Apps

AI tools (the so called 'vibe coding tools') can create an entire application (e.g., Web apps, mobile apps) based on prompts.

Examples:

C: Best Practices for AI-Assisted Coding

To effectively leverage AI in your workflow, it's crucial to adopt a set of best practices. The following tips are non-exhaustive, and should be kept in mind regardless of which AI model you use.

C1. Treat the AI as a Collaborator, Not a Replacement

Think of an AI coding assistant as a junior developer or a pair programmer. It can accelerate your work, but you are ultimately the one in charge of the final product.

AI tools are powerful, but they don't understand code in the way a human does. They are prediction engines. It is your responsibility to review, validate, and test any code generated by an AI to ensure it is efficient, secure, and correct.

Use AI to handle repetitive tasks, generate boilerplate code, brainstorm solutions, and get you unstuck. This frees you up to focus on the more complex, architectural aspects of software development. Don't let it become a crutch that hinders your own learning and skill development.

C2. Prompt Engineering

Garbage in, garbage out. The quality of an LLM's output is directly tied to the quality of your input. Crafting effective prompts is the single most important skill for working with LLMs. This whitepaper by Lee Boonstra (Software Engineer Tech Lead @ Google) outlines several key techniques:

  • Provide Examples (One-shot & Few-shot Prompting): This is described as "the most important best practice" (p. 54). Giving the model examples of what you want helps it understand your desired output structure, style, and pattern.
    • DO NOT: "Parse these contacts to JSON."
    • DO: "Parse these contacts to JSON in the following format:
      Example Input: Name: John Doe, Contact Number: 87654321, Year of Study: 2
      Expected Output:
      {
          name: 'John Doe',
          contact_number: 87654321,
          year_of_study: 2
      }
      
  • Prompt with Simplicity and Clarity: Your prompts should be concise and easy to understand. A good rule of thumb is: if the prompt is confusing to you, it will be confusing to the model.
    • DO NOT: "I'm building a user registration system for my app and I'm stuck. I need to check if the email address a user provides is valid, but I don't know the rules for a valid email. Can you help me write some Java code for this?"
    • DO: "Provide a Java method that uses regex to validate an email address format. The method should accept a String and return a boolean."
  • Be Specific About the Output: The more specific you are, the better the result. Instead of a generic request, provide details about the desired format, style, and content.
    • DO NOT: "Generate a Java class for a car."
    • DO: "Generate a public Java class named Car. The class should include private string fields for make, model, and a private int field for year. Include a constructor to initialize all fields and public getter methods for each field."
  • Use Instructions Over Constraints: Tell the model what to do rather than what not to do. Positive instructions are generally more effective and less ambiguous.
    • DO NOT: "Write a Java method that filters a list of integers to get only the even numbers. Do not use a for-loop or an if-statement."
    • DO: "Write a Java method that filters a list of integers to get only the even numbers. Use the Java Stream API ."

C3. Understand AI's Limitations

Never trust AI-generated code blindly. Models can be confidently wrong, introduce subtle bugs, or generate code with security flaws.

  • Test Extensively: Just because code looks correct and runs without errors doesn't mean it's bug-free or handles all edge cases. Write and run unit tests, integration tests, and performance tests to validate the functionality and robustness of any AI-generated code before integrating it into your projects.

D: Ethical Use of AI

It is possible to use AI tools not only as coding assistants, but also as opportunities to practice ethical judgment and critical thinking. Always document when you use AI tools, and critically evaluate outputs before adopting them into your work.

Examples:

  • It is possible to paste in code from another source and ask the AI to rewrite or optimize it, but you should clearly acknowledge the source and reflect on whether you are learning or simply copying.
  • It is possible to generate a function or algorithm using AI, but you should carefully check for bugs, inefficiencies, and security issues before integrating it, and document AI assistance if required.
  • It is possible to ask AI to produce unit tests or documentation, but you should ensure the outputs meet course standards and revise them to demonstrate your own understanding.
  • It is possible to compare AI-generated code with your own solution to learn about trade-offs in readability, maintainability, and performance, but the final submission should represent your own reasoning.
  • It is possible to rely on AI for productivity, but you should balance this with independent coding practice to avoid over-reliance.

Contributors: Dillon Tan (@dillontkh), Jay Hong (@hjungwoo01)