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.
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.