| English | 释义 | 拼音 |
|---|---|---|
| library/ˈlaɪbrəri/ | 库 | kù |
| from scratch/frɒm skrætʃ/ | 从头开始 | cóng tóu kāi shǐ |
| API/ˌeɪ piː ˈaɪ/ | 应用程序接口 | yìng yòng chéng xù jiē kǒu |
| documents/ˈdɒkjuːmənts/ | 记录 | jì lù |
| functionality/ˌfʌŋkʃəˈnælɪti/ | 功能 | gōng néng |
| abstraction/əbˈstrækʃn/ | 抽象 | chōu xiàng |
重用别人写的代码
- 一个库(library)是一组你能跨程序重用的过程。
- 与其从头开始(from scratch)写一切,你用别人已经写好并测试过的代码。
- 那节省时间并减少缺陷。
- 几乎每个真实程序都依赖库。
A library is:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
It lets you reuse code instead of writing from scratch.
阅读 API
- 要用好一个库,你阅读它的 API(应用程序接口)。
- API 记录(documents)如何使用库:它提供哪些过程、它们接收什么实参、返回什么。
- 你不需要看库内部的代码。
- API 是你和库之间的契约。

图书馆提供可通过其文档调用的经测试程序
Which library for the job?
Pick the library that matches your task: a maths library for numbers, a graphics library for drawing, a random library for random values.
A library's API tells you:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
The API documents usage; you never need the inside code.
Writing every function from scratch is safer than using a well-tested library.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
False. A well-chosen library's code has already been tested by many users, so reusing it saves time and usually reduces bugs.
快速添加功能
- 库快速给你的程序添加功能(functionality)。
- 一个数学库给平方根;一个图形库画形状;一个随机库给随机数。
- 为你需要的部分挑一个合适的库。
- 一个选得好的库节省时间并减少缺陷,因为代码已经测试过。
Calling sqrt(9) and getting 3 without knowing the method inside is an example of:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
The library hides its implementation behind a simple call.
To draw shapes on the screen, you would choose a:
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
Match the library to the kind of job you need.
r ← sqrt(2) stores about 1.414, using a ______ library.
难度 1/5 · 今日首次完成可获 100 金币及少量额外奖励
The maths library provides the tested square-root procedure.
库与抽象
- 像过程一样,库通过隐藏复杂的实现支持抽象(abstraction)。
- 你调用
sqrt(9)得到 3,而不知道内部用的方法。
2 的平方根。 与其写你自己的算法,调用一个数学库:r ← sqrt(2) 存储约 1.414。API 告诉你 sqrt 接收一个数字并返回它的平方根。整个任务变成一行。
一个库是可重用、已测试的代码,所以你不用从头开始建一切。阅读它的 API 来了解它提供哪些过程、返回什么——你从不看内部。库快速添加功能并提供抽象:sqrt(9) 给出 3,而你不知道怎么做的。