CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the...

24
CSCB09: Software Tools and Systems Programming Bianca Schroeder [email protected] IC 460

Transcript of CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the...

Page 1: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

CSCB09: Software Tools and Systems Programming

Bianca Schroeder [email protected]

IC 460

Page 2: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

2

How is everyone doing?

•  PCRS is not perfect. It’s been developed by instructors and students for free.

•  But better than the alternative: Assigning readings from the text book for class prep.

PCRS

Page 3: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

3

PCRS •  Some things to keep in mind:

–  Do not touch the lines of code that are already provided. Start below.

–  If that does not work try refresh. –  For longer code segments, write your program in a file

and compile/test with gcc.

PCRS

Page 4: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

4

Feedback •  Come and visit me in office hours. •  There is a form for anonymous feedback on the

course web page. http://www.cs.toronto.edu/~bianca/cscb09s17/feedback.shtml

PCRS

Page 5: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

5

Assignments

•  You will use a version control system (SVN) to submit your assignments.

•  What is a version control system and what is it good for?

Page 6: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

6

Why version control (I): Working from different machines

Bianca in her UTSc office

Lecture1.ppt

•  Involves a lot of copying files around •  Pain to make sure to keep versions consistent

Bianca on the TTC

Lecture1.ppt Copy

Bianca in her StG office

Lecture1.ppt Copy

Page 7: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

7

Why version control (II): Working in a team

Alice

A1.c

•  How do you coordinate changes to a file? •  Exchange emails, phone calls… –  “I’m going to work on A1.c, so don’t touch it.”

•  Painful!

Bob

Update Update

Page 8: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

8

Why version control (III): Keeping track of program changes

Alice

A1.c

•  Could periodically save backups –  Ad-hoc –  Only programmers knows versions –  Hard to pick which version to go back to –  No tools to help you

Update A1.c

Update A1.c

Update

Page 9: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

9

(Centralized) Version Control •  A master copy of all files (and their previous versions) lives at

a central server •  For each machine / team member: before first use of

repository, check out local copy –  Under svn: svn checkout <url of repository>!

9

Bianca in her UTSc office

Lecture1.ppt

Bianca on the TTC

Lecture1.ppt

Bianca in her StG office

Central server Lecture1.ppt

Master copy

Get local copy

Lecture1.ppt

Get

local copy

Repository

Page 10: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

Version control •  After making modifications to local copy of file, upload

changes to the server so others can see them –  Under svn: svn commit –m “message describing mods”!

10 10

Bianca in her UTSc office

Lecture1.ppt

Bianca on the TTC

Lecture1.ppt

Bianca in her StG office

Central server Lecture1.ppt

Master copy

Lecture1.ppt

Repository

Page 11: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

Version control •  After making modifications to local copy of file, upload

changes to the server so others can see them –  Under svn: svn commit –m “message describing mods”!

•  Note that svn stores both old and new version of file

11 11

Bianca in her UTSc office

Lecture1.ppt

Bianca on the TTC

Lecture1.ppt

Bianca in her StG office

Central server

Lecture1.ppt

Master copy

Lecture1.ppt

Lecture1.ppt Version 1

Version 2

Page 12: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

Version control •  Bianca now wants to continue working from her laptop:

–  Need to update local copy to see changes that have been “committed” to the server

–  Under svn: svn update!

12 12

Bianca in her UTSc office

Lecture1.ppt

Bianca on the TTC

Lecture1.ppt

Bianca in her StG office

Central server

Dow

nloa

d ch

ange

s

Lecture1.ppt

Lecture1.ppt

Master copy Lecture1.ppt Version 1

Version 2

Repository

Page 13: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

Version control •  Bianca now realizes that edits she made in the office

were garbgage and wants back the original (blue) version –  Under svn: svn update –r 1 (parameter to –r can ! ! ! ! ! !be any version #)

13 13

Bianca in her UTSc office

Lecture1.ppt

Bianca on the TTC

Lecture1.ppt

Bianca in her StG office

Central server

Rev

ert

back

to

vers

ion

1

Lecture1.ppt

Lecture1.ppt

Master copy Lecture1.ppt Version 1

Version 2

Lecture1.ppt

Page 14: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

Version control •  Bianca starts working in her office on a new document •  Need to tell the server to add this file

–  Under svn: svn add <filename>! svn commit –m “message here”!

•  Same for new directories

14 14

Bianca in her UTSc office

Lecture1.ppt

Bianca on the TTC

Lecture1.ppt

Bianca in her StG office

Central server

Lecture1.ppt

Lecture1.ppt

Master copy Lecture1.ppt Version 1

Version 2

Lecture1.ppt

Lab1.ppt

Lab1.ppt

Repository

Page 15: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

Version control •  Commit and update operations are automatically

applied to all repository files in the current working directory (and recursively to sub-directories) that are part of the repository

15 15

Bianca in her UTSc office

Lecture1.ppt

Bianca on the TTC

Lecture1.ppt

Bianca in her StG office

Central server

Lecture1.ppt

Lecture1.ppt

Master copy Lecture1.ppt Version 1

Version 2

Lecture1.ppt

Lab1.ppt

Lab1.ppt

Repository

Page 16: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

Version control •  What if two users modify their local copy, Alice uploads

her changes and then Charlie tries to upload changes? –  Will Charlie’s upload overwrite Alice’s changes?!

16 16

Alice

Lecture1.ppt

Bob Charlie

Central server

Lecture1.ppt Lecture1.ppt

Lecture1.ppt

Master copy Lecture1.ppt Version 1

Version 2

Repository

Page 17: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

Version control •  What if two users modify their local copy, Alice uploads

her changes and then Charlie tries to upload changes? –  Will Charlie’s upload overwrite Alice’s changes?

17 17

Alice

Lecture1.ppt

Bob

Lecture1.ppt

Charlie

Central server

Lecture1.ppt

Lecture1.ppt

Master copy Lecture1.ppt Version 1

Version 2

Repository

Page 18: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

Version control •  What if two users modify their local copy, Alice uploads

her changes and then Charlie tries to upload changes? –  Will Charlie’s upload overwrite Alice’s changes?

18 18

Alice

Lecture1.ppt

Bob

Lecture1.ppt

Charlie

Central server Lecture1.ppt

Master copy

Lecture1.ppt

No! If the master copy has changed since Charlie last

updated his local copy, when Charlie tries to commit his copy the server will notify him of the differences between his local

copy and the master copy and ask him which should prevail or

to submit a merged version.!

Page 19: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

SVN summary •  Checking out a new SVN repository:

•  svn checkout <url of repository>!

•  Committing local changes to the repository: •  svn commit –m “message describing mods”

•  Downloading updates in the repository to local copy: •  svn update

•  Adding new files/directories to the repository: •  svn add <filename>!

19 19

Page 20: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

20

Why should you learn C? The Tiobe index for the popularity of programming languages:

•  Also required in many of your future courses (operating systems, advanced databases, compilers, graphics..)!

Page 21: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

21

A sample program #include <stdio.h>!#define DAYS 4!!int main() {!! float daytime_high[DAYS] = {16.0, 12.8, 14.6, 19.1};! ! float average_temp = 0;!! int i;! for (i = 0; i < DAYS; i++) {! average_temp += daytime_high[i];! }! ! average_temp = average_temp / DAYS;! printf("average %f\n", average_temp);!! return 0;!}!

Page 22: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

22

Arrays

int x[5];!for (i = 0; i < 5; i++) {! x[i] = i*i;!}!

x[0]!

x[1]!

x[2]!

x[3]!

x[4]!?

0x88681140 0x88681144 0x88681148 0x8868114c 0x88681150 0x88681154

•  Arrays in C are a contiguous chunk of memory that contain a list of items of the same type.

•  If an array of ints contains 10 ints, then the array is 40 bytes (assuming 4 byte integers). There is nothing extra.

•  In particular, the size of the array is not stored with the array. There is no runtime checking.

Page 23: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

23

Arrays

int x[5];!for (i = 0; i <= 5; i++) {! x[i] = i*i;!}!

x[0]!

x[1]!

x[2]!

x[3]!

x[4]!

l  No runtime checking of array bounds l  Behaviour of exceeding array bounds is “undefined”

à  program might appear to work à  program might crash à  program might do something apparently random

?

0x88681140 0x88681144 0x88681148 0x8868114c 0x88681150 0x88681154

Page 24: CSCB09: Software Tools and Systems Programmingbianca/cscb09s17/posted... · Lecture1.ppt No! If the master copy has changed since Charlie last updated his local copy, when Charlie

Number representations

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 …

0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20

•  Counting in the decimal system:

Represents numbers as powers of 10, e.g. the number 1315 equals: 1 x 1000 + 3 x 100 + 1 x 10 + 5 x 1

1

•  Counting in the hexadecimal system:

Represents numbers as powers of 16, e.g. the number 1315 equals: 1 x 16^3 + 3 x 16^2 + 1 x 16^1 + 5 x 16^0