6.031 Software Construction is MIT's course on building correct, understandable, and evolvable software. I followed the 2021 (SP21) and 2022 (SP22) offerings to ground my programming in static checking, types, and the "big three" properties of good software. This Deep Dive summarizes what I took from the first two readings: Static Checking (SP21) and Basic TypeScript (SP22).
我系统学习了 MIT 6.031 的 2021 与 2022 版本,重点放在静态检查与 TypeScript 基础上,作为写好软件的第一块基石。
The course is built around three goals every program should aim for:
| Property | Meaning |
|---|---|
| Safe from bugs | Correct today and correct in the unknown future. |
| Easy to understand | Communicating clearly with future programmers, including future you. |
| Ready for change | Designed to accommodate change without rewriting. |
Static checking is the first major tool the course uses to make code safe from bugs.
Reading 1: Static Checking introduces types and the difference between static, dynamic, and no checking.
A type is a set of values plus the operations that can be performed on them.
In statically-typed languages (e.g. Java, TypeScript), variable types are known at compile time, so the compiler can catch
many errors before the program runs—such as "5" * "6" (multiplying two strings).
Catching bugs statically is better than dynamically, and dynamically is better than not at all. Static typing prevents a large class of bugs: applying an operation to the wrong types of arguments.
The reading also warns about primitive types not being true numbers: integer division truncation, integer overflow,
and floating-point special values (NaN, Infinity) that can hide errors.
Reading 2: Basic TypeScript moves from Python to TypeScript and introduces snapshot diagrams, variable declarations, and mutability.
TypeScript uses let for reassignable variables and const for unreassignable references.
Types can be annotated explicitly, e.g. let n: number = 1; and const s: string = "hello";.
Snapshot diagrams represent runtime state: the stack (methods and local variables) and the heap (objects).
Double borders denote immutable values; double arrows denote unreassignable references.
s = s + "b").arr.push("b")).
Strings are immutable; arrays are mutable.
const only makes the reference unreassignable—you can still have const arr: Array<string> = ["a"]
and then arr.push("b"). The distinction between mutability and reassignability is central to writing code that stays safe from bugs.
TypeScript’s Array is like Python’s list; Map is like a dictionary; Set is an unordered collection of unique values.
The reading maps common operations (e.g. lst.length, lst.push(e), lst.includes(e)) to their Python equivalents,
which helps when transitioning from Python to TypeScript.
const vs let.