Unit 2: Abstraction
Lab 1: Games
2.1.1:
Variable
AAP-1.A.1
A variable is like a box that can hold one value at a time, such as one word, one costume, or one list (which can contain many things). You can look at what's inside as many times as you want.
On
Unit 1 Lab 2 Page 2: Making Programs Talk, you learned about
procedural abstraction: giving scripts names by putting them in new blocks. Here, we are starting to look at
data abstraction, giving names to numbers, text, lists, etc. When you give something a name, you can refer to it without knowing exactly what the value is.
2.1.1:
Local Variable
A local variable can be set or used only in the environment in which it is defined. This term includes inputs to procedures and variables created by the for
or script variables
block.
2.1.2: Predicate and
Boolean value
Why is Boolean capitalized?
The word Boolean is capitalized because it's named after a person, George Boole, who invented the branch of mathematics dealing with Boolean operations (such as and
, or
, and not
).
A predicate is a hexagon-shaped reporter that asks a true/false question such as these examples:
AAP-2.E.1
Predicates report a Boolean value (either or ).
2.1.2
The if
and if-else
blocks are called conditionals because they control the code based on a true-or-false condition.
2.1.4:
Global Variable
A global variable is a variable that is usable by all scripts in the program.
2.1.4
Setting the starting value of a variable is known as initializing the variable.
2.1.5:
Index
The position number is called the index of the item in the list.
In this list, 1 is the index of the item "apple," 2 is the index of the item "cantaloupe," and so on.
AAP-1.D.8
In Snap! and on the AP exam, the index is always a whole number (1, 2, 3, 4, etc.). It is an error to use an index less than 1 or greater than the length of the list.
Lab 2: Making Lists
2.2.1
An element is another name for an item in a list. (If the same value is in the list twice, that counts as two different elements.) Each element has a unique index (position) in the list.
2.2.2:
Sublist
A sublist is a list used as an item of another list.
(The word sublist is also used to refer to some subset of a list.)
2.2.2: Abstract Data Types
AAP.1.D.1
The word "abstract" is often used casually to mean something harder to understand or more complex, but in computer science, its meaning is almost the opposite. ADTs are things that you, the programmer, create to make your program easier for you and others to read, debug, and improve.
-
An abstract data type (ADT) is a custom data type that's meaningful to your program. It's not built into the language; you develop it as you code. This is an abstraction because it hides the details inside the constructor and selectors so that the programmer who uses a
quiz item
has to think only about questions and answers, not about list indices.
-
The block is the constructor; it constructs one example of the data structure. By naming the pieces of the structure, the constructor makes it certain that every time you use it, you build the structure in the right order.
-
The and blocks are the selectors; they each select one piece of the data structure.
The constructor and selector together implement the
quiz item
abstract data type.
DAT-1.A.5
- Data abstraction is the creation and use of abstract data types in a program.
2.2.2:
Table
A table is a two-dimensional
data structure with rows and columns. If you've
used a spreadsheet program, what it
displays is a table.
In Snap!, a table is implemented as
a list of lists, in which each sublist is one
row of the table.
2.2.3
Using the result from item
as the input to address from contact
is called composition of functions.
2.2.3:
Traversing a List
AAP-2.O.2
Traversing a list means looking at each item of the list. For each
is iterative. That is, it's repetitive, like for
, which can also traverse a list. But unlike for
, for each
traverses the list without using index numbers.
Lab 3: Making Decisions
2.3.1: Domain and Range
- The input type (often called domain by programmers) of a function is the type of data that it accepts as input.
- The output type (often called range) of a function is the type of data that it reports as output.
2.3.1:
Sequencing, Selection, Iteration
Selection: AAP-2.G.1; sequencing, selection, iteration: AAP-2.A.4
Selection means deciding (selecting) which part of an algorithm to run based on whether a condition is true or false.
Every algorithm can be constructed using sequencing (following steps in order), selection (deciding), and iteration (repeating).
2.3.3
AAP-2.I.1
A nested conditional statement is an if
or if else
statement inside another if else
statement.
2.3.5:
String and
Index
AAP-1.C.4
- A string is an ordered sequence of characters.
AAP-1.C.3 (strings)
- You've already learned the word index for the position of an element in a list. The same word is used for the position of a character in a string (for example, a letter in a word). So the first input to
letter
is the index.
2.3.6
All the words in the puzzle are related to the AP CS Principles course.
Lab 4: Making Computers Do Math
2.4.2
A software library is a collection of procedures that can be used in programs.
2.4.2:
APIs
AAP-3.D.4, AAP-3.D.5
An application program interface (API) documents what a programmer needs to know about using a library: it's a description of each procedure's purpose, inputs, and outputs (but not its algorithms).
What is a Web API?
A common kind of API is a web API in which the library exists on someone else's computer. For example, the Google Maps API describes how to embed a Google Map on your own website.
I'm actually inclined to cut all the rest of this yellow box. --MF, 1/15/20
A web API is just a call to a procedure on another machine. For example, these are three different notations for the same procedure call, which looks up the number of searches for "BJC" in the US:
The only difference is that the URL shows where on the Internet to find the procedure.
Lab 5: Copyrights
2.5.2
IOC-1.F.5
- Creative Commons is a specific family of copyright licenses that allow others to use, share, maybe sell, and maybe revise your work.
2.5.2
IOC-1.F.5
Ideas similar to Creative Commons are used for particular kinds of material:
- Free software means software that anyone can copy, use, modify, and redistribute, including commercially, provided that any modifications must be under the same license.
Doesn't the “provided that” make it unfree?
The reason for that restriction is to prevent other people from turning a modified version of the software into non-free software with restrictive licensing. That's the only thing you're not allowed to do: make it unfree.
- Open source software is a more general term that means that you make the program's source (human-readable) code available to anyone. You may still restrict how people can use the program.
What's the point of making it available if people aren't allowed to use it?
One reason is for security software, so that people can check that the software isn't leaking your password or other data, and will therefore trust you. (One reason many people don't trust computerized voting machines is that their manufacturers keep their code secret.) Another reason for open source is that you're hoping other people will contribute improvements to your proprietary software.
- Open access scholarly research reports are available for free download, rather than requiring the permission of a journal publisher.