CS202 Review Session 1 Notes from [Xiangyu Gao](https://xiangyug.github.io/), TA from fall 2021 Edited by Khanh Nguyen, TA Spring 2022 Edited by Jinli Xiao, TA Spring 2023 1. Introduction 2. Logistics 3. Motivation & tips for success 4. Lab infrastructure 4.1. Git and GitHub 4.2. Docker 4.3. scripts and Makefile 4.4. Lab setup demo 5. Lab 1 overview 5.1. Debugging and gdb 6. Q&A -------------------------------------------------- 1. Introduction 2. Logistics - 5 optional review sessions in total, 1 hour each. - Will post the notes on course website, and recordings on Brightspace. - Provide an overview of the labs and help you with important background knowledge. - Ask me any questions. If I can't answer them, please post on Campuswire (CW). - PLEASE don't ask me if your code is correct. Labs are an opportunity for you to learn, and you should test your code. 3. Motivation & tips for success - Personally, I find the material very useful day to day in industry. You will hear terms: processes, threads and memory thrown around in technical docs as well as codebase. So I think the course prepares the foundation significantly. To succeed in cs202: - Start on time. Read through the code and lab write up before coding. Understand the overall design first. - PUT IN THE WORK. I don't mean only doing the lab. It means keeping up with the reading, reviewing notes, handouts, doing the homeworks and labs. - DON'T CHEAT. - Exam is one of the many data points. Don't get discouraged if you don't do too hot on the midterm. Pull your weight and be consistent throughout the course - Ask questions. Don't be afraid to ask questions. I will be happy to answer them. If I don't know the answer, I will find someone who does. 4. Lab infrastructure - You will need to setup Git, GitHub, and Docker. - The tools may be overwhelming at first. But for the purpose of this course, you don't need to dive too deep into them. Remember the basic commands and you will be fine. - Instructions on the course website should be detailed enough. If you have any questions, please post on CW or come to office hours. - Here I will give you a higher level overview on how these tools work together. 4.1. Git and GitHub - Git - Git is a version control system that allows developers to track and manage changes to their code. - Git also allows developers to easily revert to previous versions of their code if necessary. - It is widely used in the software development industry and is a key tool for collaboration and organization. - GitHub - Git != GitHub - GitHub is a hosting website that stores Git repositories. Alternatives are GitLab, BitBucket, etc. - GitHub hosts remote repositories that allows you to download lab starter code and upload your code for grading, with appropriate permissions. - In cs202, you need to work with three Git repositories: - nyu-cs202/labs - remote repository that contains the starter code for labs. - the course staff will release labs here. - you should not push your work to this repo; push to your private repo instead. - nyu-cs202/labs-23sp- - remote repository contains your code/submission for labs. - this repo is private and visible only to you and the course staff. DO NOT share code in this repo with anyone else. - your local repo - this is a copy of your private repo that lives on your computer. - the lab setup lets you fetch the starter code (upstream) to your local machine and work on it there. - you then push your changes to the remote private repo (origin) on GitHub. - [see diagram on the whiteboard] - My suggestions: - Try the basic commands: clone, add, commit, push, pull, fetch, merge, ... - Try interacting with the terminal. Don't rely too much on the GUI. - Note: these commands all have side effects, so try to understand what they do. - Don't be afraid to ask questions. 4.2. Docker - Operating system, installed software, and dependencies are likely different on our computers. - Virtual machine provide a way to let us use a consistent environment, but it is heavy and slow. - Docker is a lightweight alternative to virtual machines. We will use Docker for the labs. - Virtual Machine virtualizes the hardware, while Docker only virtualizes the operating system. 4.3. scripts and Makefile - scripts are a set of commands that you can run in the terminal. By putting them in a file, you can run them all at once with a single command. For example, ./cs202-run-docker is a script that runs the Docker container for you. This saves you from remembering the long Docker commands and typing them manually each time. - Recall the C compilation process. There is also a lot of steps involved. Even more so when you have multiple files. - make is a tool that helps you automate the compilation process. We setup rules in a file called 'Makefile' and you can just run each of them with a single and simple command. Eg. make, make test, etc. 4.4. Lab setup demo - [on laptop, start and run docker, edit files, compile, run, commit, push] 5. Lab 1 Overview - Lab 1 should be easier than other labs. Still, you will do a lot of setting up, review your C skills, and familiarize yourself with the lab workflow. Many things can go wrong. So remember to start on time. - The lab will help you review C and teach you to use gdb (if you haven't already used it). - If you are unsure about your C skills, I recommend looking at K&R: The C programming language. (see course homepage for more details) - Try to learn gdb on the go. It is really powerful and somewhat crucial on later labs. Your skill will improve the most when you are using it. - Remember to follow lab setup instructions to setup Docker. All your labs will be graded on the Docker environment provided. 5.1. Debugging and gdb - gdb is a debugger that allows you to step through your program and inspect the state of your program at each step. Personally, it is my favorite debugger for C. - We assume you are already familiar with C. You should spent some decent time in CSO learning C. - [live gdb demo] - Suggestions for debugging: - Don't try changing your code around without thinking about it first. It will waste lots of your time and is not cost effective. More importantly, sometimes, you won't even know why your code fails and how you ACTUALLY fix it. - Can also use printf or combination of printf + gdb. But printf is also not the greatest strategy. If you notice you rely on using printf too much, try switching to gdb. - Don't be scared of compiler warnings and errors. Compiler, most of the times, is your friend. 6. Q&A