Unit 3 · 12 min
3.2 Impact of Program Design
Good program design includes thinking about who the program might fail, harm or copy from.
Summary, objectives and course and exam description (CED) codes
System reliability means a program performs its tasks as expected under stated conditions without failure, so programmers test it with a variety of conditions. Programs affect society, the economy and culture in good and harmful ways, sometimes beyond their intended use. Reusing code raises legal and intellectual property questions: open source code is free to use, other code needs permission and often payment.
By the end of this session you can
- 3.2.A Explain the social and ethical implications of computing systems.
Reviewed against the CED on
1LearnThe notes, the traps and how to remember them
1. System reliability: test with many conditions
System reliability means the program can perform its tasks as expected under stated conditions without failure 3.2.A.1. Programmers should try to maximize reliability by testing the program with a variety of conditions 3.2.A.1.
Here is a method that turns a quiz score into a percent. It works on the first test, so it looks finished.
public class QuizScore
{
public static int percent(int correct, int total)
{
return correct * 100 / total;
}
}
System.out.println(QuizScore.percent(18, 20));
System.out.println(QuizScore.percent(0, 20));
System.out.println(QuizScore.percent(5, 0));
Output:
90
0
Exception in thread "main" java.lang.ArithmeticException: / by zero
The third test, a quiz with no questions yet, makes the program fail with a run-time error. A good test plan includes:
| Kind of test | Example input | Why |
|---|---|---|
| Typical value | 18 out of 20 | The normal case works. |
| Boundary value | 0 out of 20, 20 out of 20 | The smallest and largest results are correct. |
| Unusual value | 5 out of 0 | The program does not crash on input it did not expect. |
The improved version states its behavior for the unusual case, so it works as expected under all stated conditions:
public class QuizScore
{
/** Returns the percent correct, or 0 when total is 0 */
public static int percent(int correct, int total)
{
if (total == 0)
{
return 0;
}
return correct * 100 / total;
}
}
System.out.println(QuizScore.percent(18, 20));
System.out.println(QuizScore.percent(20, 20));
System.out.println(QuizScore.percent(5, 0));
Output:
90
100
0
2. Programs have beneficial and harmful impacts
Creating a program has impacts on society, the economy and culture, and these impacts can be both beneficial and harmful 3.2.A.2. A program meant to fill a need or solve a problem can have unintended harmful effects beyond its intended use 3.2.A.2.
| Program | Beneficial impact | Possible harmful impact |
|---|---|---|
| A route planner | Drivers save time and fuel (economy). | It sends heavy traffic through quiet streets next to a school (society). |
| A music recommendation app | Listeners discover new artists (culture). | It keeps showing the same popular songs, so small artists are heard less (culture, economy). |
| An online grade portal | Students see their progress quickly (society). | Students without home internet see it later than others (society). |
The route planner problem can start with one design choice in the code. This method only looks at travel time:
public class RoutePlanner
{
public static String choose(int mainRoadMinutes, int sideStreetMinutes)
{
if (sideStreetMinutes < mainRoadMinutes)
{
return "side street";
}
return "main road";
}
}
System.out.println(RoutePlanner.choose(14, 12));
Output:
side street
Every user gets the same answer, so thousands of cars go down the side street. A more careful design adds a condition the designers care about, such as avoiding a school zone during school hours:
public class RoutePlanner
{
public static String choose(int mainRoadMinutes, int sideStreetMinutes,
boolean schoolHours)
{
if (sideStreetMinutes < mainRoadMinutes && !schoolHours)
{
return "side street";
}
return "main road";
}
}
System.out.println(RoutePlanner.choose(14, 12, true));
System.out.println(RoutePlanner.choose(14, 12, false));
Output:
main road
side street
Watch out: on the AP® exam, an “impact” answer should name who is affected and how. “It is bad for people” is too vague; “it increases traffic danger near a school” is specific.
3. Legal issues and intellectual property
Code is intellectual property: it belongs to the person or company that wrote it. Legal issues and intellectual property concerns arise when you create programs 3.2.A.3.
- Programmers often reuse code written by others that is published as open source and free to use 3.2.A.3. Open source code comes with a license that says what you may do with it, for example that you must keep the author’s name and the license text.
- To include code that is not published as open source, the programmer must obtain permission and often purchase the code before putting it in their program 3.2.A.3.
A good habit is to record where reused code came from, right in a comment:
public class TextUtils
{
// The method below is adapted from an open source utility library.
// It is free to use under that library's license, which asks us
// to keep this notice and credit the original authors.
public static String initials(String first, String last)
{
return first.substring(0, 1) + last.substring(0, 1);
}
}
System.out.println(TextUtils.initials("Sam", "Rivera"));
System.out.println(TextUtils.initials("Lee", "Chen"));
Output:
SR
LC
| Situation | Can you use the code? |
|---|---|
| Open source library, free to use, you follow its license | Yes 3.2.A.3 |
| A company’s code you found in a leaked file | No: it is not open source and you have no permission. |
| A paid library you have not bought or licensed | Only after you obtain permission, which often means buying it 3.2.A.3 |
Lock it in: memory hooks
- ReliabilityReliable = works as expected, under the stated conditions, without failure. Test normal, edge and odd.
- ImpactsS.E.C.: society, economy, culture. Each one can gain or lose.
- Reusing codeOpen source: use it under its license. Not open source: ask, and usually pay.
Common misconceptions
"If a program works on the example input, it is reliable."
Not quite. Reliability means it works as expected under all the stated conditions. Test typical values, boundary values (like 0 or the largest allowed value) and unusual cases, not just one example.
"Code I find online is free to copy into my program."
Not quite. Code is intellectual property. Open source code published as free to use can be reused under its license terms. Code that is not open source needs the owner's permission, and often you must buy it.
"A program built to help people cannot cause harm."
Not quite. Programs made to fill a need or solve a problem can still have unintended harmful effects beyond their intended use.
Exam traps
- Reliability is about working as expected under the stated conditions, not about running fast.
- An unintended harmful effect still counts as an impact of the program, even though the programmer did not plan it.
- Code that is not open source cannot just be credited and used: the programmer must obtain permission and often purchase it.
2PracticeRecall it, then check yourself
In 30 seconds
- System reliability: the program performs its tasks as expected under stated conditions without failure.
- Maximize reliability by testing with a variety of conditions: typical, boundary and unusual inputs.
- Programs impact society, the economy and culture; the impacts can be beneficial and harmful.
- A program meant to solve a problem can have unintended harmful effects beyond its intended use.
- Open source code published as free to use can be reused; other code needs permission and often a purchase.
Cover this list, say the points out loud, then take the checkpoint without scrolling back up.
Checkpoint · 4 questions
Checkpoint: Impact of Program Design
Pick an answer to mark it. Every answer is explained, and you can try any question again. Your saved score counts first tries only, and stays in this browser.
3PrevailLock it in for exam day
By the numbers
- Areas that programs impact three areas CED 3.2.A.2
- society
- the economy
- culture
- Ways to reuse code legally two ways CED 3.2.A.3
- use code published as open source and free to use
- obtain permission (and often purchase) for code that is not open source
Key terms: flip the cards
Read the term, say the definition out loud, then flip to check. Struggling a little to remember is what makes it stick.
-
System reliabilitytap to flip
A program's ability to perform its tasks as expected under stated conditions without failure.
Example and CED codes -
Intellectual propertytap to flip
Creations of the mind, such as program code, that belong to their authors; reusing code raises legal and licensing questions.
Example and CED codes -
Open sourcetap to flip
Code that its authors publish for others to use, study and reuse, under a license that states the conditions.
Example and CED codes -
Program designtap to flip
Planning a program's classes, with each class's attributes and behaviors, in natural language or a diagram before writing code.
Example and CED codes
Questions students ask
What is system reliability in AP® Computer Science A?
System reliability means the program can perform its tasks as expected under stated conditions without failure. Programmers improve it by testing the program with a wide variety of conditions.
Can I use code from the internet in my program?
Only if you are allowed to. Open source code published as free to use can be reused by following its license. For code that is not open source, you need permission from the owner and often have to buy it.
What is an unintended harmful effect of a program?
It is harm the program causes that its designers did not plan, often when the program is used beyond its intended purpose, such as a route app that sends heavy traffic through quiet streets.