Collaboration, Program Purpose and Program Function

AP Computer Science Principles · Unit 1 — Creative Development

Why computing innovations are built by teams

A computing innovation is any innovation that includes a program as an integral part of its function: a ride-sharing app, a smart thermostat, a spreadsheet macro. Almost none of them is written by one person, and the AP framework treats collaboration as a skill, not a soft extra.

Collaboration helps in two different ways. First, it divides the work, so a larger program can be finished in the same time. Second, and more important on the exam, it brings in diverse perspectives. People with different backgrounds notice different needs, different edge cases and different kinds of bias. A team that includes users of different ages, languages or abilities is more likely to discover that a font is unreadable for older users or that a form rejects names with accents.

Common collaboration practices include pair programming (a driver types while a navigator reviews each line, and the two switch roles often), consulting and communicating with the intended users, using shared online tools so that everyone works on the current version, and giving and receiving feedback respectfully. Collaboration also includes acknowledging code, media or ideas that came from someone else: the original author or source should be credited in the program documentation.

Notice what collaboration does not guarantee. Adding people does not automatically remove bias; it helps only when the added perspectives are actually different and are actually listened to. A team of ten people who all test the app on the same phone in the same city has more hands, not more perspectives.

Purpose, function, inputs, outputs and events

The exam separates two descriptions of a program that students tend to blur. The purpose of a program is why it exists: the problem it solves or the creative interest it pursues. Its function is what it does when it runs: the behaviour a user can observe. "Help a family avoid buying food they already have" is a purpose. "Displays the items in the pantry list that expire within three days" is a function.

A program's behaviour is driven by inputs, data sent to the computer for processing. Inputs can be tactile (a tap or a click), audio (a voice command), visual (a camera frame) or text (typed characters), and they can also come from another program or a file. Outputs are data sent from the program to a device or another program: text on a screen, a sound, a vibration, a file written to disk.

Many modern programs are event-driven. An event is an action that supplies input — a button press, a key press, a mouse movement, a timer reaching zero. Each event is linked to a block of code called a handler, and that block runs when the event occurs. As a result, the statements of an event-driven program are not necessarily executed in the order in which they appear in the source code. The user's sequence of actions, not the line numbers, determines the order.

When you trace an event-driven program, therefore, list the events in the order they happen and apply each handler to the current values of the shared variables. A handler that ran earlier may have changed the values that a later handler reads.

Sự kiện quyết định khối lệnh nào chạy — không phải thứ tự dòng mã Nhấn nút "Thêm"Gõ phím EnterHẹn giờ 60 giây trình xử lý 1items ← items + 1 trình xử lý 2DISPLAY(items) trình xử lý 3items ← 0 biến chungitems Người dùng bấm theo thứ tự nào thì các trình xử lý chạy theo thứ tự đó, có thể lặp lại nhiều lần.
Chương trình hướng sự kiện. Ba sự kiện khác nhau gọi ba trình xử lý, cả ba cùng đọc/ghi biến items. Nếu người dùng nhấn Thêm hai lần, chờ hẹn giờ, rồi gõ Enter thì màn hình hiện 0 — dù dòng items ← items + 1 nằm trên cùng trong mã.

Worked example: Tách mục đích, chức năng, đầu vào, sự kiện

A student describes her app: “Many students at my school forget to drink water during exams week. My app lets a student set a daily goal in millilitres. Every time the student taps the glass icon, 250 mL is added to today's total and the progress bar grows. At 8 p.m. a timer checks the total; if it is below the goal, the phone vibrates and shows a reminder.”

Identify (1) the purpose, (2) one function, (3) two inputs of different kinds, (4) one output, and (5) explain why the reminder code does not run in the order it is written.

Solution

(1) Mục đích: giúp học sinh uống đủ nước trong tuần thi — đây là vấn đề mà ứng dụng tồn tại để giải quyết. Câu “ứng dụng cộng 250 mL” không phải mục đích, vì nó chỉ tả việc ứng dụng làm.

(2) Một chức năng: mỗi lần chạm biểu tượng cốc, cộng 250 mL vào tổng của ngày và kéo dài thanh tiến độ.

(3) Hai đầu vào khác loại: mục tiêu mL do người dùng gõ (văn bản) và cú chạm vào biểu tượng cốc (xúc giác). Sự kiện đồng hồ 20 giờ cũng là một đầu vào, đến từ hệ thống chứ không từ người dùng.

(4) Một đầu ra: điện thoại rung kèm dòng nhắc trên màn hình (hoặc thanh tiến độ dài ra).

(5) Khối nhắc là trình xử lý của sự kiện hẹn giờ 20 giờ. Nó chỉ chạy khi sự kiện đó xảy ra, nên dù được viết ở đầu hay cuối tệp mã, nó luôn chạy sau mọi cú chạm trong ngày và đọc tổng mL đã được các cú chạm đó cập nhật.

Common mistake

Bẫy “chức năng đội lốt mục đích”. Phương án nhiễu hay viết mục đích bằng động từ của máy: “chương trình hiển thị…”, “chương trình lưu…”. Cứ câu nào mô tả việc máy làm khi chạy là chức năng. Mục đích trả lời câu hỏi “để làm gì, cho ai”. Bẫy thứ hai: tưởng cộng tác tự động giảm thiên lệch. Đề thường cho một nhóm đông nhưng đồng nhất — đáp án đúng là thêm góc nhìn khác (người dùng khác nhóm, thử trên điều kiện khác), không phải thêm người.

Key takeaway

Chốt: mục đích = vì sao, chức năng = làm gì khi chạy. Đầu vào có nhiều dạng (chạm, giọng nói, hình, chữ, tệp); sự kiện là hành động cung cấp đầu vào và kích hoạt khối lệnh riêng, nên thứ tự chạy do người dùng quyết định. Cộng tác có giá trị nhất ở chỗ mang vào góc nhìn khác nhau, và mọi phần mượn của người khác phải ghi nguồn.

All AP Computer Science Principles lessons · Practice AP Computer Science Principles questions (free, instant scoring) · Program Design and Development →