Computer science, worked through

Programs, systems, and the ideas underneath.

Course notes from CS61A to CS162, an interactive introduction to Swift, and the thinking that piles up while building real projects.

One idea, four languages
The same function, as each course would write it.
func square(_ x: Int) -> Int {
    x * x
}

let squares = [1, 2, 3].map(square)
print(squares)   // [1, 4, 9]

Learn Swift

def square(x):
    return x * x

squares = list(map(square, [1, 2, 3]))
print(squares)   # [1, 4, 9]

CS61A

static int square(int x) {
    return x * x;
}

int[] squares = IntStream.of(1, 2, 3)
    .map(Main::square).toArray();   // [1, 4, 9]

CS61B

int square(int x) {
    return x * x;
}

int squares[] = {1, 2, 3};
for (int i = 0; i < 3; i++)
    squares[i] = square(squares[i]);   // {1, 4, 9}

CS61C

01

Courses

Berkeley’s CS sequence, one layer of abstraction at a time: from functions, to data structures, to the machine, to the operating system.

Data structures

CS61B

Data Structures

How data is organized, and what that costs: lists, trees, hashing, graphs, and asymptotic analysis.

Java
No notes yet

02 · Interactive tutorial

Learn Swift, one question at a time.

Modeled on the official Swift documentation and the rhythm of CS61A: a short idea, a small program, then a question about what it will do before you run it.

  • Lessons that follow CS61A, lecture by lecture
  • “What would Swift print?” checks and Parsons problems in every lesson
  • A lab at the end of each lesson, with solutions
Start learning Swift

What would Swift print?

let numbers = [3, 1, 2]
print(numbers.sorted().first!)

Type Error if running it would crash. For several lines of output, put each on its own line.

Show answer and explanation

Answer1

sorted() returns a new array, [1, 2, 3], and first is its first element. The ! unwraps the optional, which is safe here because the array is not empty.

03

Projects

Longer builds, with the reasoning behind their design.

Pingclair

A project introduction, with the design decisions and trade-offs behind it, is being written.

In progress

04

Latest writing

All writing

Nothing published yet.

The first notes will appear here once they are ready to read.