Program Function and Purpose · 程序的功能与目的
| English | 中文 | Pinyin · 拼音 |
|---|---|---|
| purpose/ˈpɜːpəs/ | 目的 | mù dì |
| function/ˈfʌŋkʃn/ | 功能 | gōng néng |
| behavior/bɪˈheɪvjə/ | 行为 | xíng wéi |
| Input/ˈɪnpʊt/ | 输入 | shū rù |
| Processing/ˈprəʊsesɪŋ/ | 处理 | chǔ lǐ |
| Output/ˈaʊtpʊt/ | 输出 | shū chū |
| events/ɪˈvents/ | 事件 | shì jiàn |
| event-driven/ɪˈvent ˈdrɪvən/ | 事件驱动 | shì jiàn qū dòng |
| event handler/ɪˈvent ˈhændlə/ | 事件处理程序 | shì jiàn chǔ lǐ chéng xù |
Purpose vs function
- Before writing code, be clear about two related ideas.
- The purpose 目的 of a program is why it exists — the problem it solves.
- The function 功能 is what it does — the behavior a user sees.
- A weather app's purpose is "help people plan"; its function is "show the forecast."
目的与功能
- 写代码之前,先弄清两个相关的想法。
- 程序的目的(purpose)是它为什么存在——它解决的问题。
- 功能(function)是它做什么——用户看到的行为。
- 一个天气应用的目的是"帮人们做计划";它的功能是"显示预报"。
Input, processing, or output? · 输入、处理,还是输出?
Every program takes input, processes it by its instructions, and produces output. Sort each part of a program into the right stage. · 每个程序接收输入,按其指令处理,并产生输出。把程序的每个部分归入正确的阶段。
A program's purpose is why it exists; its function is: · 程序的目的是它为什么存在;它的功能是:
Purpose = the goal; function = the visible behavior that reaches it. · 目的 = 目标;功能 = 达到它的可见行为。
Which is an example of input? · 哪个是输入的例子?
A tap is data the program receives; the others are outputs. · 点击是程序接收的数据;其他是输出。
The input → processing → output model
- Every program follows a simple model: input → processing → output (the IPO model).
- Input 输入: data the program receives — typing, a sensor, a file, the internet.
- Processing 处理: the steps it performs on that input.
- Output 输出: the result — text, a sound, a saved file, a robot moving.
输入 → 处理 → 输出模型
- 每个程序都遵循一个简单模型:输入 → 处理 → 输出(IPO 模型 IPO model)。
- 输入(input):程序接收的数据——打字、传感器、文件、互联网。
- 处理(processing):它对该输入执行的步骤。
- 输出(output):结果——文字、声音、保存的文件、机器人移动。
Put the IPO model in order. · 把 IPO 模型排序。
Data comes in, is processed, and a result goes out. · 数据进来,被处理,结果出去。
A program that waits and reacts to clicks and key presses is ______-driven. · 一个等待并响应点击和按键的程序是______驱动的。
Each event triggers an event handler. · 每个事件触发一个事件处理程序。
A program can give different outputs for different inputs. · 一个程序对不同的输入可以给出不同的输出。
That is exactly what a program's behavior means. · 这正是程序行为的含义。
Behavior and events
- A program's behavior 行为 is how it responds to inputs — different inputs can give different outputs.
- Many modern programs are event-driven 事件驱动: they wait and react to events 事件 like a click or a key press.
- Each event triggers a small piece of code called an event handler 事件处理程序.
- A game, a website button, and a chat app are all event-driven.
行为与事件
- 程序的行为(behavior)是它如何响应输入——不同的输入能给出不同的输出。
- 许多现代程序是事件驱动(event-driven)的:它们等待并响应事件(events),如点击或按键。
- 每个事件触发一小段代码,叫事件处理程序(event handler)。
- 一个游戏、一个网页按钮和一个聊天应用都是事件驱动的。
A well-designed program should: (Select all that apply) · 一个设计良好的程序应该:(选出所有正确项)
Good design also handles every possible input, including unusual ones. · 好的设计还处理每一个可能的输入,包括不寻常的。
What a well-designed program does
- Solves a genuine problem for its users.
- Is clear about the input it expects and the output it gives.
- Does its job reliably every time it runs.
- Thinking about every possible input is part of designing it correctly.
一个设计良好的程序做什么
- 为用户解决一个真正的问题。
- 清楚它期望的输入和给出的输出。
- 每次运行都可靠地完成它的工作。
- 思考每一个可能的输入是正确设计它的一部分。
A program's purpose is why it exists; its function is what it does. Every program fits input → processing → output (the IPO model). Its behavior is how it responds to inputs — and many programs are event-driven, reacting to clicks and key presses through event handlers.
程序的目的是它为什么存在;它的功能是它做什么。每个程序都符合输入 → 处理 → 输出(IPO 模型)。它的行为是它如何响应输入——许多程序是事件驱动的,通过事件处理程序响应点击和按键。