Unit 3, Chapter 1, Lesson 7: APIs and Using Functions with Parameters

Overview

Students will learn to read App Lab’s API documentation and will use functions that accept parameters in order to complete a series of drawing puzzles which require them to make use of the App Lab API documentation to learn new drawing commands. Many of these commands will require the use of parameters. The final challenge asks students to design a personal monogram making use of the commands they learned during the lesson.

Purpose

An API is a reference guide which catalogs and explains the functionality of a programming language. If a programmer develops the practice of referencing an API, she can make full use of that functionality without undergoing the tedium of memorizing every detail of the language. In today’s lesson, students will need to read through the API in order to find and understand new commands for moving the turtle, selecting colors, and drawing different-sized dots and lines on the screen. Students should not necessarily understand every command in the drawing API in detail, but they should be familiar with referencing the API as a standard part of the process of writing a program. This will also be the first time students are given access to drawing functions that take parameters (e.g., moveForward(40) vs. moveForward()).

Objectives

Students will be able to:

  • Use parameters to provide different values as input to procedures when they are called in a program.
  • Use API documentation to assist in writing programs.
  • Define an API as the set of commands made available by a programming language.

Vocab

  • API – a collection of commands made available to a programmer
  • Documentation – a description of the behavior of a command, function, library, API, etc.
  • Hexadecimal – A base-16 number system that uses sixteen distinct symbols 0-9 and A-F to represent numbers from 0 to 15.
  • Library – a collection of commands / functions, typically with a shared purpose
  • Parameter – An extra piece of information passed to a function to customize it for a specific need

New Code

Getting Started

  1. So far in this unit we have been exploring programming by drawing turtle art with only a few commands. It will probably not surprise you to learn that there are many more commands included in most programming languages, including the version of JavaScript included in App Lab. In fact, most programming languages include hundreds if not thousands of commands.
  2. Do you think programmers memorize all of the commands in a programming language? If not, how is anyone ever able to use an entire programming language?
  3. Programmers weren’t born knowing how a programming language works, and, like you and me, they don’t have perfect memories. Instead they rely on written documentation to help them learn new features of a language and recall how it works. Today we are going to be exploring how useful documentation can be when learning a programming language or just writing software.
    1. FYI: Programming is not some innate talent. Every programmer has to learn by seeing examples of a language being used and reading documentation. In fact, even professional programmers will frequently reference documentation while designing software. Becoming a good programmer is much less about memorizing a language and more about learning habits of mind and patterns that allow you to use a language (including its documentation) effectively!

Activity

  1. At end of the day we hope to be much more talented turtle artists, but we’re also going to be learning another important skill: reading the documentation of a programming language.
  2. Before you ask me or a classmate for help today, I want you to read through the documentation, try the examples, talk with friends, and then talk to me. It may be slower going today, but in the long term it will make you much more confident programmers.
  3. Be sure to read the explanation of the term parameter and not just skip it. It’s an important term to know.
  4. Log in to code.org
  5. Work through the lesson on your own–be sure to READ EVERYTHING!!
  6. Evaluate at least 1 program someone else did. Include the name of the person whose code you critiqued. Use the following criteria:
    1. The program draws the diamond
    2. The program defines four functions: right(); drawStep(); drawSide(); and drawDiamond(); The names are less important than the existence of four functions with this functionality.
    3. The program makes a single call to drawDiamond();
    4. The program looks clean and organized

Wrap-up

  1. The level progression for today’s lesson includes many important vocabulary words. While these levels attempt to introduce these words in the context of using them, take a moment at the conclusion of class to review the words covered and ensure students are comfortable using them.
    • Parameter: accepts a value to be passed to a function, typically affecting the behavior of that function (e.g., changing the distance the moveForward() command moves the turtle)
    • Library: a collection of commands / functions, typically with a shared purpose (e.g., a library of functions for manipulating the turtle)
    • API: application program interface, the full set of commands included in a programming language (e.g., every command made available by App Lab)
    • Documentation: a description of the behavior of a function, library, API, etc.
  2. In your Word Online file for this class, respond to the following:
    1. Multiple Choice: What is an API?
      • Abstract Programming Inheritance: The idea that abstractions in languages get “passed down” in newer versions
      • Artificial Parameter Intelligence: The idea that function parameters should be intelligent enough to “know” what you want as a programmer
      • Application Program Interface: A well-documented library of functions provided in a programming language that helps to simplify complex programming tasks.
      • Abstract Parameter Interface: A high-level description of the parameters a function accepts
    2. Multiple Choice: What is a function parameter?
      • “para-meter” — a measure of the distance between a function’s conception and implementation.
      • A way to give input to a function that controls how the function runs.
      • A collection of commands that can be used in a programming language.
      • Another name for the purpose of a function.
      • A named memory location.
    3. Free Response: It is said that functions with parameters generalize the behavior of a more specific command. Explain what this sentence means to you using the difference between turnLeft() and turnLeft(angle).

Leave a comment

Your email address will not be published. Required fields are marked *