Essential Knowledge

  • Software libraries contain procedures used in creating novel programs.
  • Existing code segments can be derived from internal or external sources: Libraries, Previously written code.
  • Libraries simplify complex programs.
  • APIs (application program interfaces) specify how procedures in libraries should behave and be utilized.
  • Documentation for APIs/Libraries are necessary to gain proper understanding into how to use them.

Vocab

Term Definition
Documentation Text that explains the what, how, or why of your code.
Libraries A collection of prewritten code or procedures that coders can use to maximize their efficiency
Application Programming Interface A type of software through several computers are able to communicate information amongst eachother

Reusing Code

To make maximize efficiency in novel code, it is best to use previously made procedures.

For example:

Alt text

The pre-existing procedure in this program is moveBackwards. This procedure orients the robot in the correct direction by rotating left twice, and then moving forward. The new procedure adds on, and moves the robot forward, right, then forward twice. This places the robot in it's final position.

Documentation

The procedure is often too long to view, unlike the previous example. So in order to know how to use it, you need documention (explanation of what the procedure does).

def gradeAverage(num):
    sumNums = 0
    for t in num:
        sumNums = sumNums + t

    average = sumNums / len(num)
    return average

print("The average grade is", gradeAverage([65, 70, 72, 75, 80, 73, 61, 84, 81, 83]))
The average grade is 74.4

Documentation for the example above: The procedure gradeAverage takes a list of integer values representing the percentages in a certain class, and returns the average of those integers.

Let's Practice!

Which of the following would be MOST useful as part of a program that determines Grade Point Average?

  1. A procedure isEqual, which takes two positive integers as input and returnes if their values are equal.
  2. A procedure calcQuotient, which takes two positive integers as input and returns their quotient.
  3. A procedure getHighGrade, which takes a list of grades as input and returns the highest value.
  4. A procedure calcStatus, which takes a positve integer credits and returns a string grade classifier (senior, junior, etc.).
Answer [2, in order to calculate a GPA, it is necessary to take sum of the letter grades' corresponding numbers, and divide them by the number of grades]

Which of the following would be LEAST useful in a program that helps choose the best restaurant within 5 miles of your location?

  1. A procedure orderReviews, which lists 10 restaurants from least to greatest based on their associated star-rating.
  2. A procedure numPeople, which outputs the name of 10 restaurants with the highest visits per month.
  3. A procedure foodItem, which lists all menu items marked vegetarian on a high rated restaurants menu.
  4. A procedure ranRest, which randomizes a list of highest rating restaurants and outputs 1 restaurant.
Answer [3, while this procedure may be useful once the restaurant is chosen, it does not help to choose the restaurant itself]

Libraries and APIs

A useful example of a Library that is provided by College Board, is the APCSP Exam Reference Sheet. The sheet contains various procedures and how they should/are used.

Appilcation Program Interface (API) gives specific directions for how procedures that reside in these APIs can be used.