0% found this document useful (0 votes)
24 views

Lect1 Introduction

Here are the key points about labs: - Weekly 100-minute lab sections led by a TA for hands-on practice - Complement lectures by allowing students to work directly with course topics - Provide opportunities to discuss concepts and code with peers under TA guidance - Start next Friday and continue throughout the semester

Uploaded by

Cem Güven
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Lect1 Introduction

Here are the key points about labs: - Weekly 100-minute lab sections led by a TA for hands-on practice - Complement lectures by allowing students to work directly with course topics - Provide opportunities to discuss concepts and code with peers under TA guidance - Start next Friday and continue throughout the semester

Uploaded by

Cem Güven
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 67

Photo: Dennis Ritchie and Ken Thompson

COMP201
Computer
Systems &
Programming
Lecture #01 – Introduction
Aykut Erdem // Koç University // Spring 2023
2
A little about me…
Koç University
Associate Professor
2020-now

Hacettepe University
Associate Professor
2010-2020 • I explore better ways to
understand, interpret
Universitá Ca’ Foscari di Venezia
Post-doctoral Researcher and manipulate visual
2008-2010 data.
Middle East Technical University
1997-2008 • My research interests
Ph.D., 2008
M.Sc., 2003 span a diverse set of
B.Sc., 2001 topics, ranging from
MIT image editing to visual
Fall 2007 saliency estimation,
Visiting Student
and to multimodal
VirginiaTech
Visiting Research Scholar
learning for integrated
Summer 2006 vision and language. https://aykuterdem.github.io
3
Plan For Today
• Course Introduction
• COMP201 Course Policies
• Unix and the Command Line
• Getting Started With C

Disclaimer: Slides for this lecture were borrowed from


—Nick Troccoli's Stanford CS107 class
4
Lecture Plan
• Course Introduction
• COMP201 Course Policies
• Unix and the Command Line
• Getting Started With C

5
What is COMP201?
• The third course in the line of COMP’s introductory programming
courses (COMP100, COMP132, and COMP201)
– COMP100 teaches you the notion of computational thinking and how to solve
problems as a programmer (using Python)
– COMP132 introduces you object-oriented programming paradigm (using Java)

• COMP201 takes you behind the scenes:


– Not quite down to hardware or physics/electromagnetism (that’s for later...)
– It’s how things work inside C++/Python/Java, and how your programs map
onto the components of computer systems
– Not only does it just feel good to know how these work, it can also inform
projects you work on in the future.
6
Role within COMP Curriculum
COMP301 COMP306
COMP304 COMP416 COMP317 COMP303
Programming Database
Operating Computer Embedded Computer
Language Management
Systems Networks Systems Architecture
Concepts Systems

Programming Processes, Data Reps. Network Execution Model


Languages Memory Memory Model Protocols Memory System
Management

COMP201
Computer Systems
and Programming

COMP100 COMP132
Intro. to CS & Advanced
Programming Programming

7
What is COMP201?
Computer Systems and Programming
• How languages like C++ and Java represent data
under the hood
• How programming structures are encoded in bits and
bytes
• How to efficiently manipulate and manage memory
• How computers compile programs
• How cache memories work and how to exploit them
to improve the performance of your programs
• Uses the C programming language
• Programming style and software development
practices

8
COMP201 Learning Goals
The goals for COMP201 are for students
to gain mastery of
- writing C programs with complex use of memory and
pointers
- an accurate model of the address space and
compile/runtime behavior of C programs

to achieve competence in
- translating C to/from assembly
- writing programs that respect the limitations of computer
arithmetic
- finding bottlenecks and improving runtime performance
- working effectively in a Unix development environment

and have exposure to


- a working understanding of the basics of cache memories
9
COMP201 Learning Goals
(also learn to identify legitimate programmer scenes in Hollywood movies)

Jeff Goldblum’s character saving the Elliot creating a malicious PDF file, which
world by uploading a virus to contains some sort of shellcode that will
the alien mothership allow him to take over any Linux
Independence Day, 1996 computer that opens that file in Evince.
Mr. Robot, S3, Ep9 -
eps3.8_stage3.torrent (2017)
Source: https://www.geekwire.com/2017/mr-robot-rewind-pwning-dark-army-episode-9/
Course Overview
1. Bits and Bytes - How can a computer represent integer numbers?
2. Chars and C-Strings - How can a computer represent and manipulate more
complex data like text?
3. Pointers, Stack and Heap – How can we effectively manage all types of
memory in our programs?
4. Generics - How can we use our knowledge of memory and data representation
to write code that works with any data type?
5. Assembly - How does a computer interpret and execute C programs?
6. The Memory Hierarchy - How does the memory system is organized as a
hierarchy of different storage devices with unique capacities
7. The Heap Allocators - How do core memory-allocation operations
like malloc and free work? 11
Teaching Team

Mert Çökelek Nafiseh Jabbari Tofighi Osman Batur İnce

Aykut Erdem

Beyza Erdogan Eda Güven Emir Gencer Sinan Aghayev

12
Course Website

https://aykuterdem.github.io/classes/comp201.s23/

*lecture videos on Panopto – can be accesses through Blackboard or from the course webpage
13
Question Break!

14
Lecture Plan
• Introduction
• COMP201 Course Policies
• Unix and the Command Line
• Getting Started With C

15
Textbooks
• Computer Systems: A Programmer’s
Perspective by Bryant & O’Hallaron,
3rd Edition
– 3rd edition matters – important updates
to course materials
• A C programming reference of your
choice
– The C Programming Language by
Kernighan and Ritchie
– Other C programming books, websites,
or reference sheets

16
Course Structure
• Lectures: understand concepts, see demos
• Labs: learn tools, study code, discuss with peers
• Assignments: build programming skills, synthesize lecture/lab content

Monday Wednesday Friday


Lecture Lecture Lab-A-B

• assg0: out next week, due Mar 16


• C bootcamp: this week (details will be announced soon)
17
Grading
27% 5 Programming assignments
28% 9 Labs
20% Midterm exam
20% Final exam
5% Class participation

18
Grading
27% Programming assignments
28% Labs
20% Midterm exam
20% Final exam
5% Class participation

19
Assignments
• 5 programming assignments completed
individually using Unix command line tools
– Free software, pre-installed on linuxpool cluster
dedicated to COMP students
– GitHub Classroom
– We will give out starter projects for each
assignment
• Graded on functionality (behavior) and style
(elegance)
– Functionality graded using automated tools, given
as point score
– Style graded via automated tests and TA code
review,
– Grades returned via Blackboard
20
Late Policy
• Start out with 7 grace days: each late day allows you to submit an
assignment without penalty if you have free grace days left.
• Hard deadline: No submissions will be accepted 48 hours after the
original due date of an assignment
• Penalty per day after grace days are exhausted
– 1 day: 20% off
– 2 days: 40% off

• Submissions made on Blackboard at 00:01am after the deadline counts as late and are
considered as using 1 grace day

21
Grading
27% Programming assignments
28% Labs
20% Midterm exam
20% Final exam
5% Class participation

22
Lab Sections
• Weekly 100-minute labs led by a TA, starting next Friday.
• Hands-on practice with lecture material and course topics.
+ linuxpool.ku.edu.tr
• Graded on attendance + participation (verified by submitting lab work)
– Two graded part:
– In-class practice problem (40%)
– After-class problem (60%)
– Your lowest 2 scores will be dropped, hence there will be no make-up

According to the Council of Higher Education’s decision,


both the lectures and the labs will be delivered online until April!
23
Grading
27% Programming assignments
28% Labs
20% Midterm exam
20% Final exam
5% Class participation

24
Midterm and Final Exams
• Face-to-face exams
– Midterm: At week 7, exact date and time will be announced later
– Final: Date and time will be announced later

• The exams will be released in multiple sessions, in which each student


is required to complete each session in a limited time.

25
Grading
27% Programming assignments
28% Labs
20% Midterm exam
20% Final exam
5% Class participation

26
What foreign TV series
are you watching now?
Just specify the one
that you are enjoying
the most!

27
Question Break!

28
Getting Help
• Post on the Discussion Forum at Blackboard
– Online discussion forum for students; post questions, answer other students’
questions
– Best for general assignment questions (DON’T POST ASSIGNMENT CODE!)

• Visit Office Hours


– More info to come soon!

• Email the Course Staff


– Best for private matters (e.g. grading questions).

29
Koç University Honor Code
• For assignments students should be required to digitally add and approve a
version of the agreement below.
I hereby declare that I have completed this examination individually, without support
from anyone else.
I hereby accept that only the below listed sources are approved to be used during this
open-source examination:
(i) Coursebook,
(ii) All material that is made available to students via Blackboard for this course, and
(iii) Notes taken by me during lectures.
I have not used, accessed or taken any unpermitted information from any other
source. Hence, all effort belongs to me.

30
Honor Code and COMP201
• Please help us ensure academic integrity:
– Indicate any assistance received on HW (books, friends, etc.).
– Do not look at other people's solution code or answers
– Do not give your solutions to others or post them on the web or to the forum.
– Report any inappropriate activity you see performed by others.

• Assignments are checked regularly for similarity with help of automated


software tools.
• If you realize that you have made a mistake, you may retract your submission
to any assignment at any time, no questions asked. Come to use before we
come for you.
• If you need help, please contact us and we will help you.
– We do not want you to feel any pressure to violate the Honor Code in order to succeed
in this course.
31
Poll Time

32
Lecture Plan
• Introduction
• COMP201 Course Policies
• Unix and the Command Line
• Getting Started With C

33
What is Unix?
• Unix: a set of standards and tools commonly used in software development.
– macOS and Linux are operating systems built on top of Unix

• You can navigate a Unix system using the command line (“terminal”)
• Every Unix system works with the same tools and commands

34
What is the Command Line?
• The command-line is a text-based interface (i.e., terminal interface) to
navigate a computer, instead of a Graphical User Interface (GUI).

Graphical User Interface Text-based interface


35
Command Line vs. GUI
Just like a GUI file explorer interface, a terminal interface:
• shows you a specific place on your computer at any given time.
• lets you go into folders and out of folders.
• lets you create new files and edit files.
• lets you execute programs.

Graphical User Interface Command-line interface


36
Why Use Unix / the Command Line?
• You can navigate almost any device using the same tools and commands:
– Servers
– Laptops and desktops
– Embedded devices (Raspberry Pi, etc.)
– Mobile Devices (Android, etc.)

• Used frequently by software engineers:


– Web development: running servers and web tools on servers
– Machine learning: processing data on servers, running algorithms
– Systems: writing operating systems, networking code and embedded software
– Mobile Development: running tools, managing libraries
– And more…

• We’ll use Unix and the command line to implement and execute our programs.
37
Demo: Using Unix and the Command Line

38
Unix Commands Recap
• cd – change directories (..)
• ls – list directory contents
• mkdir – make directory
• emacs – open text editor Lab 1:
• vi – open text editor The Linux Shell
(next week)
• rm – remove file or folder
• man – view manual pages

See the Resources page of the course website for more commands, and
a complete reference.
39
Learning Unix and the Command Line
• Using Unix and the command line can be intimidating at first:
– It looks retro!
– How do I know what to type?

• It’s like learning a new language:


– At first, you may have to constantly look things up (Resources page on course
website!)
– It’s important to spend as much time as possible (during labs and assignments)
building muscle memory with the tools

40
Question Break!

41
Additional Reading 1

https://spectrum.ieee.org/tech-history/cyberspace/the-strange-birth-and-long-life-of-unix
42
Lecture Plan
• Introduction
• COMP201 Course Policies
• Unix and the Command Line
• Getting Started With C

43
The C Language
C was created around 1970 to make writing Unix and Unix tools easier.
• Part of the C/C++/Java family of languages (C++ and Java were
created later)
• Design principles:
– Small, simple abstractions of hardware
– Minimalist aesthetic
– Prioritizes efficiency and minimalism over safety and high-level abstractions

44
C vs. C++ and Java
They all share: C doesn’t have:
• Syntax • More advanced features like
• Basic data types operator overloading, default
arguments, pass by reference,
• Arithmetic, relational, and logical classes and objects, ADTs, etc.
operators
• Extensive libraries (no graphics,
networking, etc.) – this means
not much to learn C!
• many compiler and runtime
checks (this may cause security
vulnerabilities!)
45
Programming Language Philosophies
• C is procedural: you write functions, rather than define new variable
types with classes and call methods on objects. C is small, fast and
efficient.
• C++ is procedural, with objects: you write functions, and define new
variable types with classes, and call methods on objects.
• Python is also procedural, but dynamically typed: you still write
functions and call methods on objects, but the development process is
very different.
• Java is object-oriented: virtually everything is an object, and everything
you write needs to conform to the object-oriented design pattern.
46
Why C?
• Many tools (and even other languages, like Python!) are built with C.
• C is the language of choice for fast, highly efficient programs.
• C is popular for systems programming (operating systems, networking,
etc.)
• C lets you work at a lower level to manipulate and understand the
underlying system.

47
Programming Language Popularity
Guess which one is
the C language?

https://www.tiobe.com/tiobe-index/ 48
Programming Language Popularity
Guess which one is
the C language?

https://www.tiobe.com/tiobe-index/ 49
Programming Language Popularity
Guess which one is
the C language?

https://www.tiobe.com/tiobe-index/ 50
Programming Language Popularity

https://www.tiobe.com/tiobe-index/ 51
Our First C Program
/*
* hello.c
* This program prints a welcome message
* to the user.
*/
#include <stdio.h> // for printf

int main(int argc, char *argv[]) {


printf("Hello, world!\n");
return 0;
}

52
Our First C Program
/*
* hello.c
* This program prints a welcome message
* to the user.
*/
#include <stdio.h> // for printf

int main(int argc, char *argv[]) {


printf("Hello, world!\n");
return 0;
}
Program comments
You can write block or inline comments.

53
Our First C Program
/*
* hello.c
* This program prints a welcome message
* to the user.
*/
#include <stdio.h> // for printf

int main(int argc, char *argv[]) {


printf("Hello, world!\n");
return 0;
} Import statements
C libraries are written with angle brackets.
Local libraries have quotes:
#include "lib.h"

54
Our First C Program
/*
* hello.c
* This program prints a welcome message
* to the user.
*/
#include <stdio.h> // for printf

int main(int argc, char *argv[]) {


printf("Hello, world!\n");
return 0;
}

main function – entry point for the program


Should always return an integer (0 = success)
55
Our First C Program
/*
* hello.c
* This program prints a welcome message
* to the user.
*/
#include <stdio.h> // for printf

int main(int argc, char *argv[]) {


printf("Hello, world!\n"); Main parameters – main takes two parameters,
return 0; both relating to the command line arguments
} used to execute the program.

argc is the number of arguments in argv


argv is an array of arguments (char * is C string)
56
Our First C Program
/*
* hello.c
* This program prints a welcome message
* to the user.
*/
#include <stdio.h> // for printf

int main(int argc, char *argv[]) {


printf("Hello, world!\n");
return 0;
}

printf – prints output to the screen


57
Familiar Syntax
int x = 42 + 7 * -5; // variables, types
double pi = 3.14159;
char c = 'Q'; /* two comment styles */

for (int i = 0; i < 10; i++) { // for loops


if (i % 2 == 0) { // if statements
x += i;
}
}

while (x > 0 && c == 'Q' || b) { // while loops, logic


x = x / 2;
if (x == 42) { return 0; }
}

binky(x, 17, c); // function call

58
Boolean Variables
To declare Booleans, (e.g. bool b = ____), you must include stdbool.h:
#include <stdio.h> // for printf
#include <stdbool.h> // for bool

int main(int argc, char *argv[]) {


bool x = 5 > 2 && binky(argc) > 0;
if (x) {
printf("Hello, world!\n");
} else {
printf("Howdy, world!\n");
}
return 0;
}

59
Boolean Expressions
C treats a nonzero value as true, and a zero value as false:

#include <stdio.h>

int main(int argc, char *argv[]) {


int x = 5;
if (x) { // true
printf("Hello, world!\n");
} else {
printf("Howdy, world!\n");
}
return 0;
} 60
Console Output: printf
printf(text, arg1, arg2, arg3);

// Example
char *classPrefix = "COMP";
int classNumber = 201;
printf("You are in %s%d", classPrefix, classNumber); // You are in COMP201

printf makes it easy to print out the values of variables or expressions.


If you include placeholders in your printed text, printf will replace each
placeholder in order with the values of the parameters passed after the text.

%s (string) %d (integer) %f (double)


61
Additional Reading 2

https://arstechnica.com/features/2020/12/a-damn-stupid-thing-to-do-the-origins-of-c/
62
Question Break!

63
Writing, Debugging and Compiling
We will use:
• the vi/emacs text editor to write our C programs
• the make tool to compile our C programs
• the gdb debugger to debug our programs
• the valgrind tools to debug memory errors and measure program
efficiency

64
Demo: Compiling And
Running A C Program

args.c

65
Working On C Programs Recap
• ssh – remotely log in to linuxpool computers (later)
• Vi/Emacs – text editor to write and edit C programs
– Use the mouse to position cursor, scroll, and highlight text
– :w / Ctl-x Ctl-s to save, :q / Ctl-x Ctl-c to quit
• make – compile program using provided Makefile
• ./myprogram – run executable program (optionally with arguments)
• make clean – remove executables and other compiler files
• Lecture codes are accessible at course webpage

66
Recap
• COMP201 is a programming class, which uses
C to teach you about what goes on under the
hood of programming languages and software.

• We’ll use Unix and command line tools to


write, debug and run our programs.
• Please regularly visit the course website,
https://aykuterdem.github.io/classes/comp201.s23
and follow the announcements on Blackboard.
• We’re looking forward to an exciting semester!
Next time: How a computer represents integer
numbers? What are the limitations?
67

You might also like