# PHAS0100 - Week 6 (24th February 2023)
## C++ Tooling
This week we'll be playing with some tools for making C++ development easier and safer.
## Before You Begin
**Please clone the exercise repository for this week and build your dev container before class.**
You can clone [this week's exercise repo](https://github.com/UCL-PHAS0100-22-23/week6_tooling_exercises).
Each exercise folder has its own devcontainer so you should open them individually in VSCode instead of the entire repo.
**You can also work in the github codespaces for these exercises if your dev container is being unresponsive.**
`CMakeLists.txt` files are provided for each folder. You can build each using the commands from inside the appropriate folder:
```bash=
cmake -B build
cmake --build build
```
You will then find the executable in `build` inside that folder.
## Timetable for this afternoon
| Start | End | Topic |
| -------- | -------- | -------- |
| 14:00 | 14:10 | Unit testing quiz |
| 14:50 | 15:10 | Unit testing in the assignment |
| 15:10 | 15:20 | Break |
| 15:20 | 15:30 | Debugging with VSCode, Valgrind and compiler warnings |
| 15:30 | 15:50 | Bug hunt OR tooling in the assignment |
| 15:50 | 16:00 | Break |
| 16:00 | 16:20 | Bug hunt continued |
| 16:20 | 16:50 | Profiling demo & exercises |
## Section 1: Unit Testing
### Part 1: Quiz
Go to mentimeter.com and put in the code.
### Part 2: Unit testing in the assignment
The point of this part is to give you some feedback on how you're using unit tests in your assignment.
You should have already written some unit tests as part of your assignment (it's particularly good practice to write unit tests as you develop) but if you haven't, this is your chance to load up your assignment, add some now and get some feedback. The instructors and tutors will be moving around and asking to see your unit tests. Since you are being examined we cannot give particularly specific feedback on your unit tests, but we can help guide you towards good testing practices.
## Section 2: Debugging
### Part 1: Debugging quiz
Go to mentimeter.com and put in the code.
### Part 2: Debugging demo
See zoom for the live demo. The code can be found in the examples repo in folder `01_debugging_demo`. You should follow along and make sure you're able to find and fix all the bugs the instructor finds.
### Part 3a: Bug hunt
In the examples repo you'll find a folder called `02_bug_hunt`. This contains a longer version of the `Array` class used in Part 1 and contains *far* more bugs than in the demo. There is around 13 (intentional) bugs in this code and you will have to use Valgrind, compiler warnings and the VSCode debugger to find them all! Please feel free to work in groups with different people using different tools.
### Part 3b: Practise with tools in the assignment
In this part you should set up the following tools and test them out on your assignment:
1. Compiler warnings
2. `clang-tidy`
3. `clang-format`
4. `valgrind`
You should refer to [the week 6 notes](https://github-pages.ucl.ac.uk/research-computing-with-cpp/06tooling/) for more information about using these tools with CMake and VScode.
## Section 3: Profiling and timing
### Part 1: Timing code walkthrough
See zoom. The demo code can be found in folder `03_timing_demo`.
### Part 2: Timing exercisess
1. Change the number of values $N$ in each min calculation and see how the runtime changes
2. Change the number of iterations `N_ITERATIONS` and see if the measurement changes
3. Compare the performance when you build using CMake's `Debug` and `Release` builds. What is CMake actually changing here?
4. Implement a new function to find the minimum using the [C++ standard library](https://en.cppreference.com/w/cpp/algorithm/min_element) and time it. How does it compare to the manual methods?