Week 3 - Defining and Using Functions
Learning Objectives
Upon finishing this learning module, you should be able to:
- Identify the parameters and return type of functions
- Trace code involving function calls
- Use a unit testing framework to test functions
Recommended Schedule
Day 1
- Turn in assignment 2 if you haven't already
- Start on Functions (Ch 5.1-5.5)
Day 2
- Continue Functions (Ch 5.5-5.11)
- At this point you should be ready to do Ch 5 the exercises
Day 3
- Testing (Ch 5.12-5.16)
- Start in on assignment 3.
Day 4
Functions
Work through Chapter 5.1-5.11 of the book.
After you have read 5.11, watch this video to learn how to easily write doxygen comments in VS Code:
Testing
Read Ch 5.12-5.16 about testing and watch these videos:
For how to do this in a Codespace, watch the following video:
These two pages are a reference for using the Unit Testing framework. Use them if you quickly review how to use Doctest:
Debugger Practice
Watch this video on using the debugger to step through code that uses functions:
Then try the Debugger Practice activity linked in Module 3 of the course.
Setting Up a Local Development Environment
There are two ways you can work on your machine.
The simplest way is to use a local copy of VS Code to connect to a GitHub Codespace. You are still really working on a virtual machine in the cloud (and have limited free hours each month), but the experience is a bit better than using Codespaces in a browser.
More complex is to install everything you need on your local machine. This is more work to set up, but once it is done you can work without worrying about running out of Codespace hours. It also gives you a more realistic experience of how software development is done in the real world.
You can get through this course just fine using Codespaces.
If you are only taking CS161 (Cybersecurity), you can probably get by just using Codespaces. In that case, don't worry about setting up a local environment unless you want to. You may still want to try using a Codespace locally.
If you are going to continue to CS162 (CS and Engineers), you will eventually want to set up a local environment. So give that a try now. If everything works perfectly, great, you can start using that environment. If you run into problems, you can always fall back to using Codespaces while you get your local environment set up.
Full Local Install
To work locally, you will need to install a code editor (VS Code), a compiler (g++), and Git. Follow the instructions in this guide to set everything up:
https://computerscience.chemeketa.edu/guides/vscode-setup/
Using Codespace Locally
Using a codespace in a browser is convenient, but it can be slow and clunky. You can use VS Code on your local machine to connect to a codespace, which often gives a much better experience.
Doing this yourself is not mandatory, but it is recommended. Especially if you are going to be going on in the CS sequence to 162.
To try this out:
Start by installing VS Code on your local machine: https://code.visualstudio.com/download
Once it is installed, open the extensions view (Ctrl-Shift-X or Command-Shift-X) and search for "Codespaces" and install the extension. More on installing extensions in VS Code
This video demonstrates the setup and use of a Github Codespace in VS Code on your local machine: