Day 14 - Libraries and APIs
Day 14: Libraries and APIs
Learning Objectives
- AAP-3.D: Select appropriate libraries or existing code segments to use in creating new programs.
- AAP-3.E: For generating random values: Write expressions to generate possible values.
- AAP-3.F: For simulations: Explain how computers can be used to represent real-world phenomena or outcomes.
Essential Questions
- How do libraries and APIs help programmers build on existing code?
- How do we effectively use code written by others in our own programs?
Materials Needed
- Presentation slides on libraries and APIs
- Programming environment with available libraries
- Library exploration worksheet
- API documentation examples
- Exit ticket templates
Vocabulary
- Library
- API (Application Programming Interface)
- Package
- Module
- Import
- Documentation
- Random number generation
- Method
- Function call
- Dependency
Procedure (50 minutes)
Opening (8 minutes)
-
Review and Connection (3 minutes)
- Review function design and documentation from previous lesson
- Connect to today's focus on using existing libraries and APIs
-
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)
-
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
-
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
- Walk through examples of using library functions:
-
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)
-
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
-
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
- Formative: Quality of library exploration and usage during hands-on activities
- Exit Ticket: Effectiveness of library function usage in the program
Differentiation
For Advanced Students
- Challenge them to combine multiple library functions in sophisticated ways
- Introduce more complex libraries or APIs
- Have them create documentation for a custom library
For Struggling Students
- Provide guided examples of library function usage
- Focus on a smaller set of well-documented library functions
- Offer templates for incorporating library functions
Homework/Extension
- Complete a worksheet with library function exercises
- Research a specialized library and create a program that uses it
- Create a reference guide for commonly used library functions
Teacher Notes
- Emphasize that professional programmers regularly use libraries
- Watch for confusion about which functions are built-in vs. from libraries
- Make connections to real-world software development practices
- Consider discussing open-source libraries and community contributions
- Remind students that understanding API documentation is a critical skill