Day 14 - Libraries and APIs

Day 14: Libraries and APIs

Learning Objectives

Essential Questions

Materials Needed

Vocabulary

Procedure (50 minutes)

Opening (8 minutes)

  1. Review and Connection (3 minutes)

    • Review function design and documentation from previous lesson
    • Connect to today's focus on using existing libraries and APIs
  2. Warm-up Activity (5 minutes)

    • Present a complex task (e.g., creating a graph, generating random numbers)
    • Ask students how long they think it would take to code this from scratch
    • Introduce the concept of leveraging existing code through libraries

Main Activities (32 minutes)

  1. Lecture: Using Existing Libraries and APIs (12 minutes)

    • Define libraries as collections of pre-written code that can be reused
    • Explain the benefits of using libraries:
      • Saves development time
      • Provides tested, reliable functionality
      • Enables complex features without understanding all details
      • Promotes code reuse and standardization
    • Introduce APIs as specifications for how to use library procedures
    • Discuss different types of libraries:
      • Standard libraries (built into the language)
      • Third-party libraries
      • Custom libraries
    • Explain how to use libraries in programs:
      • Importing/including libraries
      • Reading documentation
      • Calling library functions
      • Handling return values
    • Focus on the RANDOM function as an example:
      • Syntax: RANDOM(a, b)
      • Purpose: generating random integers
      • How randomness is used in programs
  2. Demo: Incorporating Library Functions in Programs (8 minutes)

    • Walk through examples of using library functions:
      • Generating random numbers for games or simulations
      • Using math libraries for complex calculations
      • Utilizing string processing libraries
      • Working with data structure libraries
    • Show how to read and interpret API documentation
    • Demonstrate how to use library functions with different parameters
    • Show examples of combining multiple library functions
    • Highlight the importance of understanding function specifications
  3. Hands-on: Exploring Available Libraries (12 minutes)

    • Students work in the programming environment
    • Guide students through exploring available libraries
    • Have students experiment with different library functions
    • Students create programs that use library functions for tasks like:
      • Creating a random number guessing game
      • Implementing a simple simulation
      • Performing complex mathematical operations
      • Processing and formatting data
    • Encourage students to consult documentation to understand function usage

Closing (10 minutes)

  1. Activity: Solving Problems Using Appropriate Libraries (5 minutes)

    • Present students with several programming problems
    • Students identify which library functions would be useful for each problem
    • Students implement a solution for one problem using library functions
    • Share and discuss different approaches
    • Highlight how libraries simplified the solutions
  2. Exit Ticket and Preview (5 minutes)

    • Students create a program that effectively uses library functions
    • Preview that next class will focus on program development with functions

Assessment

Differentiation

For Advanced Students

For Struggling Students

Homework/Extension

Teacher Notes