MIT 6.031 软件构造 · 开篇与课程概览
课程:MIT 6.031 — Software Construction(软件构造),Spring 2022 课程主页:https://web.mit.edu/6.031/www/sp22/ 授课形式:每周一、三、五,各 90 分钟(MWF 11:00–12:30) 先修课程:6.009(Fundamentals of Programming) 本笔记基础:对课程公开站点 sp22(Spring 2022,主讲站点)与 sp21(Spring 2021,Java 版同一课程)的全部公开页面进行系统抓取后撰写,覆盖 Reading 1–29 全部章节。
关于本笔记的语言说明(请先读这段)
MIT 6.031 在 Spring 2022(sp22) 学期把授课语言从 Java 切换为 TypeScript。因此:
- 你指定的 sp22 站点上,所有代码示例都是 TypeScript。
- 但本笔记按你的要求,全部代码示例提供 Java 版本。
- 这些 Java 示例并非杜撰:它们来自 MIT 6.031 的 sp21(Spring 2021)Java 版同一门课、同一套讲义。sp22 与 sp21 的阅读材料在讲解文字上几乎逐段对应(例如 Reading 11 的正文两版高度一致,只有代码从 Java 换成了 TypeScript),所以 Java 示例与 sp22 的讲解是精确对应的,只是换了语言载体。
- 少数 sp22 特有的机制(
Promise/async/await、结构化类型系统、readonly)在 Java 中没有一一对应的孪生章节,笔记中会明确标注为「Java 类比 / 补充说明」。 - 每篇笔记开头的引用块都会说明该讲的语言对应情况。
结论:你可以把本笔记当作「用 Java 讲的 6.031」来学——概念、术语、章节结构完全忠实于 sp22 原版,代码可以在 JDK 17+ 上编译运行。
课程概览
一、这门课到底在教什么
6.031 的目标可以用一句话概括:学会写出好的代码。而”好”被精确定义为三个可检验的属性,它们贯穿全课程、出现在每一次作业评分、每一次代码审查、每一道测验题中:
| 属性 | 英文 | 含义 |
|---|---|---|
| 免于 bug | Safe from bugs (SFB) | 今天正确,并且在未知的未来依然正确 |
| 易于理解 | Easy to understand (ETU) | 与未来的程序员(包括未来的你自己)清晰沟通 |
| 易于修改 | Ready for change (RFC) | 设计上能够适应变化,而不需要推倒重写 |
这三个目标(6.031 内部常缩写为 SFB / ETU / RFC,或”the big three”)是本课程最重要的单一思想。每一个设计原则、每一种语言特性、每一条编码规范,最终都要回答同一个问题:它如何让代码更 SFB、更 ETU、或更 RFC? 在本笔记中,你会反复看到这个三元组被用来评估一个做法是好是坏。
值得强调的是:这三个目标经常互相冲突。过度抽象会让代码难以理解;为了让代码容易修改而引入的间接层可能引入 bug;为了安全性做的防御性拷贝可能损害性能。软件构造的核心技能,正是在具体语境下做出有意识的权衡,而不是机械套用规则。
二、课程范围:一张知识地图
6.031 的知识体系可以分成四个层次,这也是本笔记 29 讲的推进顺序:
第一层:代码层面的正确性与表达力(Reading 1–9)
- 静态检查(R1):让编译器在运行前抓住错误。类型系统是最廉价的测试。
- 基础语言机制(R2):原始类型与引用类型、
final、快照图(snapshot diagram)。 - 测试(R3):测试优先编程(test-first programming)、输入空间划分、边界值、代码覆盖率——测试不是事后验证,而是设计活动。
- 代码审查(R4):DRY、fail fast、魔法数字、命名、作用域。
- 版本控制(R5):Git 的对象图模型,为什么版本控制同时服务于三大目标。
- 规格说明(R6–R7):本课程的第一个理论高峰。规格说明是方法与其调用者之间的契约,由前置条件与后置条件构成;规格说明的强弱可以比较;应当使用声明式而非操作式规格;应当允许实现自由度(underdetermined)。
- 可变性与不可变性(R8):别名(aliasing)是可变对象危险的根源;防御性拷贝;不可变对象天然免于 bug。
- 避免调试(R9):把 bug 消灭在设计阶段——让 bug 不可能、让 bug 显而易见、让 bug 尽早失败。
第二层:数据抽象——本课程的核心(Reading 10–17)
- 抽象数据类型(ADT)(R10):用操作集合而非内部表示来定义类型;creators / producers / observers / mutators 四类操作的划分;表示独立性(representation independence)。
- 抽象函数与表示不变量(R11):全课程最重要的两个概念。AF 回答”内部表示代表什么抽象值”,RI 回答”内部表示的哪些状态是合法的”。二者必须写在代码注释里,由
checkRep()检查。 - 接口、泛型与枚举(R12):接口与实现分离、子类型、Liskov 替换原则。
- 调试(R13):科学方法式调试——观察、假设、实验、重复。
- 递归(R14):递归分解、基础情形与递归步骤、辅助函数。
- 相等性(R15):等价关系三性质;引用相等 vs 值相等;
equals()/hashCode()的契约。 - Map / Filter / Reduce(R16):一等函数、高阶函数、用函数抽象控制流。
- 递归数据类型(R17):不可变列表
ImList、递归类型的 AF/RI。
第三层:从数据到系统(Reading 18–27)
- 正则表达式与文法(R18)、解析器(R19):用文法描述输入语言,用解析器生成器把字符序列变成解析树,再转成抽象语法树。
- 回调与 GUI(R20):控制反转、事件循环、观察者模式——并在此引入并发的动机。
- 并发(R21–R24):本课程的第二个理论高峰。
- 共享内存 vs 消息传递两大模型(R21);
- 竞态条件与交错(R21、R23);
- 异步计算与 Promise(R22);
- 互斥:锁、
synchronized、临界区、死锁与锁顺序(R23); - 消息传递:阻塞队列、生产者-消费者模式(R24)。
- 网络(R25):客户端/服务器架构、套接字、字节流协议。
- 小语言(R26–R27):把文法、递归数据类型、解释器、访问者模式串成一条完整链路——这是全课程的”毕业设计级”综合应用。
第四层:工程与社会(Reading 28–29)
- 软件工程伦理(R28):四种道德透镜(后果主义、义务论、美德伦理、社会契约)、ACM 道德准则、伦理案例分析。
- 团队版本控制(R29):功能分支、拉取请求、合并与冲突解决、团队工作流。
三、课程哲学:为什么 6.031 这样设计
1. 软件构造的本质是”管理复杂性”。 课程反复强调:代码是写给人读的,只是顺便让机器执行。随着系统变大,唯一能限制复杂度的武器是抽象(abstraction)与模块化(modularity)。ADT、规格说明、不变量的共同目的,都是把”需要同时考虑的东西”变少。
2. 规格说明优先于实现。 6.031 的观点是:在写实现之前,你必须先能精确说出这个函数”做什么”(而不是”怎么做”)。规格说明让调用者与实现者解耦(decoupling)——调用者只依赖契约,实现者可以自由更换算法与数据结构。这就是 RFC 的技术基础。
3. 正确的做法是让错误不可能发生,而不是事后检查。 这条原则贯穿全课程:静态类型检查优于运行时断言,不变量优于临时检查,不可变对象优于防御性拷贝,编译期错误优于运行期错误。”Fail fast”(尽早失败)是它的一种表现:错误越早暴露,定位成本越低。
4. 测试是设计活动,不是收尾工作。 测试优先编程(test-first programming)要求先写测试再写实现。这不仅提高测试质量,更重要的是强迫你在写代码前想清楚规格说明和边界情况。
5. 迭代与反馈是学习的核心机制。 课程刻意压缩讲授时间、增加练习时间。每周 3 次课、每次课先来一个 3 分钟 nanoquiz;每个 Problem Set 走 alpha → 同伴代码审查 → beta 迭代 的流程;最后还有三人团队项目(Star Battle)。课程引用了 Wieman 等人的 Course Transformation Guide 和 Deslauriers 等人的物理课堂研究来论证这一设计。
6. 工程决策包含伦理维度。 最后一讲(R28)提醒:写出”技术上正确”的软件还不够,工程师要对软件的社会后果负责。这在三大目标之外增加了一个维度:软件是否对使用者与社会负责任。
四、6.031 的核心方法论:一句话总结每一层
| 层次 | 核心问题 | 主要武器 |
|---|---|---|
| 写单个函数 | 它”应该做什么”? | 规格说明(前置/后置条件)、测试优先、静态检查 |
| 写一个数据类型 | 内部表示代表什么?何时合法? | AF、RI、表示独立性、checkRep() |
| 写一个模块 | 模块之间如何解耦? | 接口、封装、信息隐藏、设计模式 |
| 写一个并发程序 | 交错执行下如何保持正确? | 不可变性、锁、消息传递、避免死锁 |
| 写一个系统 | 客户端与服务器如何通信? | 协议、套接字、字节流、抽象边界 |
| 做一个工程决策 | 这样做对谁有好处、对谁有风险? | 四大道德透镜、ACM 道德准则 |
五、评测与学习方式
| 项目 | 占比 | 内容 |
|---|---|---|
| Quizzes | 24% | Quiz 1(12%)+ Quiz 2(12%),闭卷,可带一张双面笔记纸 |
| Problem sets | 54% | PS0(6%)+ PS1–PS4(各 12%) |
| Code review | 5% | 同伴代码审查的参与度与评论质量 |
| Project | 7% | 三人团队项目 ⭐️⚔️(Star Battle) |
| Classwork | 10% | 课前阅读练习的努力 + nanoquiz 成绩 + 课堂练习 |
给自学者(如你)的建议:6.031 的知识密度很高,但它的学习曲线设计得很友好——每一讲都建立在前面几讲之上。建议的学习路径是:
- 按顺序读本笔记的 Reading 1–15,把 AF/RI(R11)和规格说明(R6–R7)读三遍,这两处是整门课的地基。
- 每读完一讲,把笔记里的错误代码先自己改对,再看正确代码。
- Reading 16–19 是”数据 → 语言”的桥梁,务必动手写一个小的解析器。
- Reading 21–24 是并发,必须动手跑代码:写一个
counter++的竞态程序,亲眼看它出错,比读十遍文字都有效。 - 最后用 Reading 26–27 的小语言把前面所有知识串起来。
文档结构导航
| 部分 | 内容 |
|---|---|
| 第一部分 | 课程资料获取与结构化整理记录:抓取范围、公开性说明、35 条公告、日程映射、作业/项目/测验记录、课程政策与评分标准、29 条结构化阅读记录 |
| 第二部分 | 分讲学习笔记 Reading 1–29(每讲统一七节结构) |
| 第三部分 | 软件构造核心原则速查表(按类别汇总规则与代码模板) |
第一部分:课程资料获取与结构化整理记录
1.1 数据获取范围与方法
本次整理对 MIT 6.031 的两个完全公开的课程站点进行了系统性抓取与文本抽取:
| 站点 | 角色 | 语言 | 抓取页面数 |
|---|---|---|---|
https://web.mit.edu/6.031/www/sp22/ | 主站点(用户指定学期,Spring 2022) | TypeScript | 53 |
https://web.mit.edu/6.031/www/sp21/ | Java 孪生版本(同一门课,Spring 2021) | Java | 54 |
为什么要抓两个站点? 用户要求提供 Java 代码示例,而 sp22 学期的 6.031 已把授课语言从 Java 切换为 TypeScript。所幸 sp21(Spring 2021)是同一门课、同一套讲义的 Java 版本, 其讲解文字与 sp22 几乎逐段一一对应(例如 Reading 11 “Abstraction Functions & Rep Invariants” 两版正文高度一致,只有代码从 Java 换成了 TypeScript)。 因此本笔记采用 sp22 的章节结构、主题顺序与术语体系,同时以 sp21 的 Java 原文 作为全部代码示例的权威来源,从而既满足”以 sp22 为准”的要求,又满足”提供可运行 Java 代码”的要求。
抓取到的原始材料保存在 /home1/runguoli/learning/mit6031_data/:
mit6031_data/
├── sp22/ # 53 个页面:29 篇 Reading + 5 个 Problem Set + Project + Quiz Archive
│ # + General/FAQ/协作政策/代码审查政策/评分政策/公告存档
├── sp21/ # 54 个页面:30 篇 Reading(Java 版)+ 作业与政策页
├── readings_index.json # 29 条结构化阅读记录(见 1.6)
├── build_index.py # 结构化提取脚本
└── crawl.py # 抓取与 HTML→文本 抽取脚本
抽取出的纯文本(.txt)保留了原文的正文、代码块、表格与列表结构,用于后续笔记撰写。
1.2 公开性说明(哪些能拿到、哪些受限)
| 资源 | 是否公开 | 说明 |
|---|---|---|
| 29 篇 Reading 正文(sp22) | ✅ 完全公开 | 含完整讲解、代码示例、图片说明、在线练习题 |
| 30 篇 Reading 正文(sp21,Java) | ✅ 完全公开 | Java 代码示例的权威来源 |
| Course Schedule / 阅读材料清单 | ✅ 公开 | 以主页面 “Readings” 索引 + 各 Reading 页形式提供 |
| Problem Set 0–4 Handout(描述文档) | ✅ 公开 | 含作业目标、截止日期、设计要求、评分说明 |
| Project Handout(Star Battle 团队项目) | ✅ 公开 | 含迭代计划、里程碑日期、团队要求 |
| Quiz Archive(历年测验与解答 PDF) | ✅ 公开 | Fall 2021 / Spring 2021 等学期 |
| General Info & FAQ、协作政策、代码审查政策、评分细则 | ✅ 公开 | 见 1.7 |
| Announcements(35 条公告) | ✅ 公开 | 见 1.3 |
| 本学期的 Quiz 1 / Quiz 2 题目与解答 | ❌ 受限 | 托管在 quiz.mit.edu,仅 MIT 学生可访问;仅题目名称公开 |
| Problem Set 起始代码仓库(starter code) | ❌ 受限 | 通过 github.mit.edu 发放,仅选课学生可访问 |
| Didit / Omnivore / Caesar / Piazza / Gradescope | ❌ 受限 | 自动评分、成绩、同伴代码审查、讨论区,均需 MIT 账号 |
| 课堂 nanoquiz、课堂练习、clicker 题目 | ❌ 受限 | 仅课堂内进行,不公开 |
| TypeScript Tutor 在线练习 | ⚠️ 部分 | 练习正文与题目出现在 Reading 页中(公开),交互式作答需登录 |
说明:受限资源的处理方式遵照任务要求——仅记录名称并注明”未公开”,不尝试绕过任何访问限制。
1.3 公告(Announcements)记录
sp22 学期共 35 条公告,按时间倒序排列如下(完整正文已保存于 mit6031_data/sp22/announcements.txt):
| 日期 | 公告主题 |
|---|---|
| Thu May 19 | Project, Quiz 2, and final grades |
| Fri May 13 | Quiz 2 today |
| Fri May 6 | Project, reflection, and last class |
| Tue May 3 | Quiz 2 during final exam period |
| Fri Apr 29 | Problem Set 4 grades |
| Wed Apr 27 | Problem Set 4 reflection |
| Sun Apr 24 | Project groups and handout |
| Fri Apr 22 | Problem Set 4 alpha reports |
| Wed Apr 20 | Problem Set 4 code review open, due Friday 11am |
| Fri Apr 15 | Project group signup |
| Fri Apr 15 | Problem Set 3 grades |
| Mon Apr 11 | Problem Set 4 |
| Fri Apr 8 | Problem Set 3 alpha reports |
| Wed Apr 6 | Problem Set 3 code review open, due Friday 11am |
| Mon Mar 28 | Quiz 1 grades |
| Fri Mar 18 | Problem Set 2 grades |
| Fri Mar 18 | Problem Set 3 |
| Thu Mar 17 | Quiz 1 tomorrow |
| Tue Mar 15 | Problem Set 2 reflection |
| Fri Mar 11 | Problem Set 2 alpha reports |
| Wed Mar 9 | Problem Set 2 code review open, due Friday 11am |
| Tue Mar 8 | Quiz 1 next week |
| Fri Mar 4 | Problem Set 1 grades |
| Mon Feb 28 | Problem Set 2 |
| Fri Feb 25 | Problem Set 1 alpha reports |
| Thu Feb 24 | no class on Friday because of snow |
| Wed Feb 23 | Problem Set 1 code review open, due Friday 11am |
| Fri Feb 18 | Problem Set 0 grades |
| Mon Feb 14 | Problem Set 1 |
| Fri Feb 11 | Problem Set 0 alpha reports |
| Wed Feb 9 | Problem Set 0 code review open, due Friday 11am |
| Mon Jan 31 | Problem Set 0 and Getting Started |
| Mon Jan 31 | Reading exercises, nanoquizzes, and other classwork |
| Sun Jan 30 | Getting started in 6.031 |
| Wed Jan 19 | Welcome to 6.031! |
公告中体现的关键学期节点:
- Wed Jan 19:欢迎来到 6.031(课程开始)
- Sun Jan 30 / Mon Jan 31:Getting started、Problem Set 0 发布、阅读练习与 nanoquiz 机制说明
- Wed Feb 9 / Fri Feb 11:PS0 代码审查开放(周五 11am 截止)→ PS0 alpha 报告发布
- Mon Feb 14:Problem Set 1 发布
- Thu Feb 24:因暴雪周五停课(说明课程会因天气调整)
- Thu Mar 17 / Fri Mar 18:Quiz 1
- Mon Mar 28:Quiz 1 成绩发布
- Fri Apr 15:项目分组报名(Project group signup)
- Sun Apr 24:项目分组与项目 Handout 发布
- Mon Apr 25:团队契约(team contract)截止
- Fri May 6:最后一节课 + 项目截止(22:00)+ 个人反思截止(22:00)
- Fri May 13:Quiz 2(1:35–2:25pm,期末考试时段)
- Thu May 19:项目成绩、Quiz 2 成绩、最终成绩归档
公告中还明确了考试纪律:Quiz 闭卷、闭笔记,允许携带 一张 8.5×11 英寸双面手写/打印笔记纸;Quiz 2 覆盖 Reading 1–29,重点为 Reading 17–29。
1.4 课程日程与阅读材料映射
6.031 每周三次课(周一/周三/周五,各 90 分钟)。大部分课程要求课前完成阅读 + 在线练习(课前晚 10pm 截止),每次课以 3 分钟 nanoquiz 开始。 下表给出 sp22 的 29 篇阅读材料、主题、对应作业,以及本笔记使用的 Java 源章节:
| Reading | 主题(sp22 原版) | 本笔记 Java 代码来源 | 相关作业 | 公开性 |
|---|---|---|---|---|
| 1 | Static Checking | — | Problem Set 0 | ✅ 公开 |
| 2 | Basic TypeScript | sp21 Reading 02: Basic Java | Problem Set 0 | ✅ 公开 |
| 3 | Testing | — | Problem Set 1 | ✅ 公开 |
| 4 | Code Review | — | — | ✅ 公开 |
| 5 | Version Control | — | — | ✅ 公开 |
| 6 | Specifications | — | Problem Set 1 | ✅ 公开 |
| 7 | Designing Specifications | — | Problem Set 1 | ✅ 公开 |
| 8 | Mutability & Immutability | — | — | ✅ 公开 |
| 9 | Avoiding Debugging | — | Problem Set 2 | ✅ 公开 |
| 10 | Abstract Data Types | — | Problem Set 2 | ✅ 公开 |
| 11 | Abstraction Functions & Rep Invariants | — | Problem Set 2 | ✅ 公开 |
| 12 | Defining ADTs with Interfaces, Generics, Enums, and Functions | — | Problem Set 2 | ✅ 公开 |
| 13 | Debugging | — | — | ✅ 公开 |
| 14 | Recursion | — | — | ✅ 公开 |
| 15 | Equality | — | Problem Set 3 | ✅ 公开 |
| 16 | Map, Filter, Reduce | — | Problem Set 3 | ✅ 公开 |
| 17 | Recursive Data Types | — | Problem Set 3 | ✅ 公开 |
| 18 | Regular Expressions & Grammars | — | Problem Set 3 | ✅ 公开 |
| 19 | Parsers | — | Problem Set 3 | ✅ 公开 |
| 20 | Callbacks and Graphical User Interfaces | — | — | ✅ 公开 |
| 21 | Concurrency | — | Problem Set 4 | ✅ 公开 |
| 22 | Promises | 无直接对应(用 CompletableFuture 类比) | Problem Set 4 | ✅ 公开 |
| 23 | Mutual Exclusion | — | Problem Set 4 | ✅ 公开 |
| 24 | Message-Passing | — | Problem Set 4 | ✅ 公开 |
| 25 | Networking | — | Problem Set 4 | ✅ 公开 |
| 26 | Little Languages I | — | — | ✅ 公开 |
| 27 | Little Languages II | — | — | ✅ 公开 |
| 28 | Ethical Software Engineering | — | — | ✅ 公开 |
| 29 | Team Version Control | — | Project ⭐️⚔️ (Star Battle) | ✅ 公开 |
关于 Quiz 覆盖范围:Quiz 1 覆盖 Reading 1–16;Quiz 2 覆盖 Reading 1–29(重点 17–29)。
1.5 作业、项目与测验记录
Problem Sets(共 5 个,占总成绩 54%)
| 作业 | 主题 | 训练目标(摘自 Handout) | Alpha | Code review | Beta |
|---|---|---|---|---|---|
| PS0 | Turtle Graphics(海龟绘图) | 课程入门、TypeScript/Git/VS Code 工具链、快照图、静态检查 | Feb 7 | Feb 11 | Feb 14 |
| PS1 | Flashcards(抽认卡) | 测试优先编程与规格说明:给定规格写单测,再实现;并强化一个规格 | Feb 22 | Feb 25 | Feb 28 |
| PS2 | Cityscape(城市天际线) | 设计与实现可变 ADT:规格由课程给定,练习 AF/RI 与 checkRep | Mar 7 | Mar 11 | Mar 14 |
| PS3 | Memely(表情包) | 解析器、递归数据类型、不可变类型的相等性;规格可自行加强 | Apr 4 | Apr 8 | Apr 11 |
| PS4 | Memory Scramble(记忆翻牌) | 并发共享可变数据类型 + 客户端/服务器系统(HTTP 协议) | Apr 19 | Apr 22 | Apr 25 |
每个 PS 采用 alpha → 同伴代码审查 → beta 迭代 的流程:alpha 提交后接受评分与同学代码审查,beta 需根据审查意见与失败测试修订代码。总评成绩约各占一半。
Project(占总成绩 7%):名称为 ⭐️⚔️(Star Battle),三人一组,要求设计、实现、测试、文档全面参与,团队统一评分。 里程碑:团队契约(Apr 25)→ Iteration #0(Apr 28)→ Iteration #1(May 3)→ 项目截止与个人反思(May 6, 10pm)。
Quizzes(占总成绩 24%):Quiz 1(12%)与 Quiz 2(12%,期末考试时段)。春季学期 Quiz 1 在 Mar 17 左右,Quiz 2 在 May 13。 Quiz 通过 quiz.mit.edu 在线进行,闭卷,允许一张双面笔记纸。Quiz Archive 公开(Fall 2021、Spring 2021 的 Quiz 1/Quiz 2 及解答 PDF,以及 Fall 2020 及更早的 Java 版测验)。
1.6 结构化阅读记录(readings_index.json)
按照任务要求,每篇阅读材料都建立了一条结构化记录。完整 JSON 保存于 /home1/runguoli/learning/mit6031_data/readings_index.json,字段格式如下:
{
"reading_number": 11,
"topic": "Abstraction Functions & Rep Invariants",
"sp22_url": "https://web.mit.edu/6.031/www/sp22/classes/11-abstraction-functions-rep-invariants/",
"key_concepts_raw": ["invariants", "representation exposure", "abstraction functions", "representation invariants"],
"related_problem_set": "Problem Set 2",
"primary_language_sp22": "TypeScript",
"java_source_url": "https://web.mit.edu/6.031/www/sp21/classes/11-abstraction-functions-rep-invariants/",
"available_public_info": "阅读材料页面完全公开,含完整讲解文本、代码示例、练习题与解答。"
}
全部 29 条记录的关键概念(key_concepts_raw,从各 Reading 的 “Objectives” 小节自动提取):
| Reading | 关键概念(原文提取) |
|---|---|
| 1 | static typing;the big three properties of good software;Hailstone sequence |
| 2 | Learn basic JavaScript and TypeScript syntax and semantics;Transition from writing Python to writing TypeScript;Getting started with TypeScript |
| 3 | understand the value of testing, and know the process of test-first programming;;be able to judge a test suite for correctness, thoroughness, and size;;be able to design a test suite for a function by partitioning its input space and choosing good test cases;;be able to judge a test suite by measuring its code coverage; and;Validation |
| 4 | code review: reading and discussing code written by somebody else;Code review |
| 5 | Know what version control is and why we use it;Understand how Git stores version history as a graph;Practice reading, creating, and using version history;Introduction |
| 6 | Understand preconditions and postconditions in function specifications, and be able to write correct specifications;Be able to write tests against a specification;Understand how to use exceptions;Introduction |
| 7 | Understand underdetermined specs, and be able to identify and assess specs that are not deterministic;Understand declarative vs. operational specs, and be able to write declarative specs;Understand strength of preconditions, postconditions, and specs, and be able to compare spec strength;Be able to write coherent, useful specifications of appropriate strength;Introduction |
| 8 | Understand mutability and mutable objects;Identify aliasing and understand the dangers of mutability;Use immutability to improve correctness, clarity, & changeability;Creating and using objects;reading exercises;Classes and objects |
| 9 | First defense: make bugs impossible;The best defense against bugs is to make them impossible by design. |
| 10 | Abstract data types;Representation independence;Introduction |
| 11 | invariants;representation exposure;abstraction functions;representation invariants |
| 12 | interfaces: separating the interface of an ADT from its implementation;;generic types: defining a family of ADTs using generic type parameters;;enumerations: defining an ADT with a small finite set of values;;global functions operating on an opaque type: rare in TypeScript but common in non-object-oriented languages.;define ADTs using classes, interfaces, generics, and enumerations;determine whether one type is a subtype of another |
| 13 | The topic of today’s class is systematic debugging. |
| 14 | be able to decompose a recursive problem into recursive steps and base cases;know when and how to use helper functions in recursion;understand the advantages and disadvantages of recursion vs. iteration;Recursion |
| 15 | Understand the properties of an equivalence relation.;Understand equality for immutable types defined in terms of the abstraction function and in terms of observation.;Differentiate between reference equality and object equality.;Differentiate between observational and behavioral equality for mutable types.;Introduction |
| 16 | (本讲 Objectives 为段落式描述,见正文) |
| 17 | Understand recursive data types;Read and write data type definitions;Understand and implement functions over recursive data types;Understand immutable lists and know the standard operations on immutable lists;Know and follow a recipe for writing programs with ADTs;Introduction |
| 18 | Understand the ideas of grammar productions and regular expression operators;Be able to read a grammar or regular expression and determine whether it matches a sequence of characters;Introduction;grammars, with productions, nonterminals, terminals, and operators;regular expressions |
| 19 | Be able to use a grammar in combination with a parser generator, to parse a character sequence into a parse tree;Be able to convert a parse tree into a useful data type;Parser generators |
| 20 | (本讲 Objectives 为段落式描述,见正文) |
| 21 | The message passing and shared memory models of concurrency;Concurrent processes and threads, and time slicing;The danger of race conditions;Concurrency;Multiple computers in a network;Multiple applications running on one computer |
| 22 | This reading discusses concurrent computation using promises.;Then we will dig below the covers to understand more about what is really happening with Promise, await, and async.;Promises |
| 23 | Library example;```;// Book represents a physical copy of a book.;// Equality operation is ===, safe for use in sets and maps.;class Book { … };// User represents a human patron of the library. |
| 24 | Two models for concurrency;In our introduction to concurrency, we saw two models for concurrent programming: shared memory and message passing.;[图: shared memory] |
| 25 | (本讲 Objectives 为段落式描述,见正文) |
| 26 | (本讲 Objectives 为段落式描述,见正文) |
| 27 | Visitors are a common feature of little languages implemented as recursive data types.;Functions on recursive types;declare the operation as an instance method in the interface that defines the data type, and;implement the operation in each concrete variant.;```;Formula = Variable(name:string) |
| 28 | Explain the ethical principles to consider when you design, build, and maintain software.;Apply four different moral lenses as you examine the ethical ramifications of a particular system.;SFB, ETU, and RFC |
| 29 | Review Git basics and the commit graph;Practice multi-user Git scenarios;Git workflow |
1.7 课程政策与评分标准记录
评分构成(摘自 General Information 的 Grading 小节)
| 项目 | 占比 | 细则 |
|---|---|---|
| Quizzes | 24% | Quiz 1 占 12%,Quiz 2 占 12% |
| Problem sets | 54% | PS0 占 6%,PS1–PS4 各占 12% |
| Code review | 5% | 由是否持续参与、评论是否实质有用评判 |
| Project | 7% | 三人团队项目,团队统一评分 |
| Classwork | 10% | 课前阅读练习的努力程度 + nanoquiz 成绩 + 课堂练习努力程度 |
字母等级默认分界:≥90 为 A,≥80 为 B,≥70 为 C;分界线只可能下调,绝不上升,且无名额限制、不按比例给分。
课堂与考勤政策
- 每周三次 90 分钟课程,必须出席并积极参与;需自带笔记本电脑。
- 每次课以 3 分钟闭卷 nanoquiz 开始,考查本次阅读与近期课堂内容。
- 自动丢弃最低 5 次课堂成绩(相当于自动豁免最多 5 次课),也可按流程补课获得部分学分。
- 课程刻意减少讲授时间、增加练习时间,因为「练习与反馈是学习的关键」(引用 Wieman 等、Deslauriers 等的研究)。
协作与公开分享政策(Collaboration and Sharing)
| 行为 | 是否允许 | 说明 |
|---|---|---|
| 向本学期 6.031 教职员求助 | ✅ 鼓励 | 一对一、Piazza、课程网站材料均可 |
| 与当前 6.031 同学协作 | ⚠️ 有限 | 仅鼓励高层次讨论;禁止代码级交流,包括伪代码 |
| 通过 MIT 项目(如 HKN)的辅导员求助 | ⚠️ 有限 | 适用与”同学协作”相同的规则 |
| 向非 6.031 教职员/学生求助 | ❌ 禁止 | 需先获教师许可 |
| 查阅非自己编写的代码 | ⚠️ 有限 | 6.031 语境下产出的代码禁止查阅(本学期教职员发放的除外);外部代码必须正确署名 |
| 分享自己写的代码 | ❌ 禁止 | 任何形式均禁止,包括公开 GitHub/GitLab 仓库 |
核心精神:讨论思路可以,逐步算法说明(含伪代码)不可以;帮助别人时,自己的代码不应可见(”帮助同学时先关掉自己的代码”)。 代码审查中会看到同学的解答,可以受启发,但不能抄袭。
代码审查政策(Code Reviewing):课程鼓励 “review-before-commit”(Google 源码仓库要求任何一行代码都必须被另一位工程师阅读、反馈并签署)。 审查的目标是 safe from bugs / easy to understand / ready for change。审查清单包括: bug 或潜在 bug、重复代码(DRY)、代码与规格不一致、off-by-one、全局变量与过大的变量作用域、魔法数字、可以更防御性或更快失败的代码、 不清晰的代码、糟糕的命名、不一致的缩进、可简化的控制流、单行/单方法塞入过多内容、晦涩代码缺注释、与代码冗余的琐碎注释、一变量多用、 语言误用(如 == vs ===、var vs let、for...in vs for...of),以及对课程已讲授设计概念(ADT、规格说明、不变量等)的误用或未使用。
求助渠道政策:一般问题走 Piazza(不要把代码贴到 Piazza);成绩问题不走 Piazza,也不直接联系助教,而是通过专门流程; TS Tutor 的 bug 用练习内的 “Report a Problem” 上报;提问时须给出可点击的精确 URL(课程网站每个段落都可链接)。
