teaching machines

CS 330: Lecture 20 – Midterm Review

Dear students, Today we’ll go over the midterm together. It’s too good an opportunity to pass up. A bunch of problems that you’ve all looked at before class. Sincerely,

CS 330: Midterm

See the PDF.

CS 330: Lecture 19 – Vtables

Dear students, Did you know that in the early days of C++, it was just a thin veneer over C? Classes were just syntactic sugar. We might have had a class that looked like this: class Hero { public: Hero(char *name, int hp) { this->name = strdup(name); this->hp = hp; } void cure(int boost) { […]

CS 330: Lecture 18 – Memory

Dear students, We’ve been talking about memory a fair bit lately, and I think it’s helpful that we have a clear picture of what’s happening when we run an executable. So, let’s have a quick discussion. When we double-click on a program or invoke it in the shell, the machine code for that program gets […]

CS 330: Lecture 17 – Subtype Polymorphism

Dear students, As we discussed last time, polymorphism is the pursuit of code that works with many types. It manifests itself in several forms that we’ve been discussing: Coercion, in which we have a value of type X and an operation that expects type Y, but there’s a known path for converting Xs into Ys. […]

CS 330: Lecture 16 – Ad Hoc Polymorphism Continued

Dear students, As we discussed last time, polymorphism is the pursuit of code that works with many types. It manifests itself in several forms that we’ve been discussing: Coercion, in which we have a value of type X and an operation that expects type Y, but there’s a known path for converting Xs into Ys. […]

CS 330: Lecture 15 – Ad Hoc Polymorphism

Dear students, As we discussed last time, polymorphism is the pursuit of code that works with many types. It manifests itself in several forms: Coercion, in which we have a value of type X and an operation that expects type Y, but there’s a known path for converting Xs into Ys. The function is polymorphic […]

CS 330: Lecture 14 – Polymorphism and More Type Safety

Dear students, Like we’ve been saying, type systems keep you from invoking illegal operations on data. A good type system will alert us when we write code like this: char alphabet[] = "abcdefghijklmnopqrstuvwxyz"; char c4 = 4[alphabet]; printf("c4: %c\n", c4); Actually, this code compiles—without warnings—and runs just fine. Because array subscripting is commutative: a[2] is […]

CS 330: Lecture 13 – Types: Safe vs. Unsafe

Dear students, While you’re waiting for class to start, here’s a little exercise for you to discuss with your neighbor: How would you write an algorithm for computing the score of a hand of Blackjack? Face cards are worth 10, aces are worth 1 or 11, and everything else is worth its rank. Sum up […]

CS 330: Lecture 12 – Type Systems Continued

Dear students, Last time, we introduced types as one of the distinguishing features of a programming language. We enumerated a bunch of types commonly supported in programming languages and distinguished between static, dynamic, and duck typing. The first two identify the time at which types are inspected, and the latter referring to the idea that […]

1 2 3 4 5 35