|
| 1 | +# Reviewing code |
| 2 | + |
| 3 | +Let us get familiar with code review tools and practices. |
| 4 | + |
| 5 | +Deadline: **December 17, 2025, 9:00** |
| 6 | + |
| 7 | +**Note:** This is the first time that we have this exercise. Feedback and suggestions is very welcome - [open an issue](https://github.com/Simulation-Software-Engineering/Lecture-Material/issues). |
| 8 | + |
| 9 | +## Overview |
| 10 | + |
| 11 | +In this exercise, you will work responsibly with AI tools to write and review code. |
| 12 | +More specifically, you will: |
| 13 | + |
| 14 | +1. use [Responsible AI](https://rai.uni-stuttgart.de) to write a simulation program, |
| 15 | +2. create a repository and publish the first implementation as a pull request to your main branch, |
| 16 | +3. review the code as if it was written by another human, |
| 17 | +4. use [GitHub copilot](https://docs.github.com/en/copilot) to conduct an automated review, |
| 18 | +5. compare the two reviews to each other and to examples from your challenge project. |
| 19 | + |
| 20 | +In the end, you will need to open an issue in the [exercise repository](https://github.com/Simulation-Software-Engineering/reviewing-exercise) with name `[username] Reviewing exercise submission`. |
| 21 | + |
| 22 | +## Generate code |
| 23 | + |
| 24 | +Generating code can be very useful to kick-start a project or to fill rather clear code parts (such as basic tests or documentation). |
| 25 | +With the right prompts and some iterations, one can create functional programs. |
| 26 | + |
| 27 | +**Important note:** Always check for mistakes and check everything you do not understand with the respective documentation. |
| 28 | +You are entering dangerous territory: AI tools have particular strengths, but also weaknesses, and they will very often confidently give wrong answers (and code with bugs), which might not be immediately visibly wrong. |
| 29 | +You remain in control and responsible for your projects. |
| 30 | + |
| 31 | +Now that we have set some guidelines, let's see the strengths in action: |
| 32 | + |
| 33 | +1. Login to the [Responsible AI](https://rai.uni-stuttgart.de) provided by the University of Stuttgart. |
| 34 | +2. In your own words, ask the tool to generate code for solving a heat equation, in a programming language you understand (e.g., Python). |
| 35 | + Ask it to take parameters from a configuration file and write results to an output file. |
| 36 | + Ask for some documentation, tests, or anything else you would like to see in such a code. |
| 37 | +3. Create a repository on GitHub (under your namespace) and initialize it with a `README.md` file. |
| 38 | +4. Add the files that RAI created to the repository, in a branch called `feature`. In your commit message, clearly disclose the tool. For example: |
| 39 | + |
| 40 | + ```text |
| 41 | + I acknowledge the use of RAI (https://rai.uni-stuttgart.de/) to implement the entirety of this code. |
| 42 | +
|
| 43 | + Promts: |
| 44 | + 1. I would like a Python script that solves the heat equation. |
| 45 | + 2. ... |
| 46 | + ``` |
| 47 | + |
| 48 | + The more details you add, the better. |
| 49 | + |
| 50 | +5. Open a merge request from the branch `feature` to the `main` branch. |
| 51 | + |
| 52 | +## Review the code |
| 53 | + |
| 54 | +Assume that this code was written by another human being. Be kind and thorough, and leave some comments in the pull request. Make sure to: |
| 55 | + |
| 56 | +- Describe what you understand this PR does. |
| 57 | +- Does the code run? Does it do the right thing? |
| 58 | +- Mention what you like about it |
| 59 | +- Add [inline comments and at least one inline code suggestion](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/commenting-on-a-pull-request) |
| 60 | +- Question parts that do not make sense to you - ask for clarifications. Are the "why" and "how" clear? |
| 61 | +- Could parts of the code be made simpler? |
| 62 | +- Comment on individual aspects such as documentation, testing, design, corner cases, and potential bugs. See the [Google Reviewer Guidelines](https://google.github.io/eng-practices/review/reviewer/) for some ideas. |
| 63 | + |
| 64 | +Your goal with any code review is to help the author improve the contribution to a state that can be accepted into the project. |
| 65 | + |
| 66 | +Start an issue in the [exercise repository](https://github.com/Simulation-Software-Engineering/reviewing-exercise) and add a link to your repository and this PR. Give a summary: what did the AI tool do nicely, where did it fail? |
| 67 | + |
| 68 | +## Get an automated review |
| 69 | + |
| 70 | +GitHub Copilot can automatically review a pull request. Add it as a reviewer and wait for it to submit a review. |
| 71 | + |
| 72 | +Carefully go through the review. Apply comments you agree with, comment on the points you don't agree with. |
| 73 | + |
| 74 | +Optional: Give [custom instructions to Copilot](https://docs.github.com/en/copilot/tutorials/customization-library/custom-instructions) (such as [code reviewer](https://docs.github.com/en/copilot/tutorials/customization-library/custom-instructions/code-reviewer)). |
| 75 | + |
| 76 | +In the issue you just opened, edit the description and comment: |
| 77 | + |
| 78 | +- Comparing the two reviews, what did Copilot focus on, what did you focus on? |
| 79 | +- What did you learn from the suggestions? |
| 80 | + |
| 81 | +## Examples from your Challenge project |
| 82 | + |
| 83 | +In the issue you just opened, edit the description and: |
| 84 | + |
| 85 | +- Add 1-3 examples of pull/merge requests with extensive review. |
| 86 | +- Comment: What do reviewers seem to typically focus on? |
0 commit comments