# Lesson 8: The Design Recipe

## Overview

In the last stage, students wrote some very simple functions - but more sophisticated functions demand a more thoughtful approach. The Design Recipe is a structured approach to writing functions that includes writing a purpose statement and test cases to ensure that the function works as expected. Once students have mastered the Design Recipe process, they can apply it to any word problem they encounter.

## Purpose

The Design Recipe process for writing functions introduces students to some best practices in software design that most don't learn until college or later. By writing examples (or test cases, as they are often called in industry) before writing the body of the function students are following a practice called test-driven development. In TDD software developers write failing test cases before adding a new features, and then works on their code until the test cases pass. This ensures that developers stay focused on writing code that does what they set out to do while also putting in place automated testing that ensures the program continues working as expected while more features are added.

## Anchor Standard

### Common Core Math Standards

• F.BF.1 - Write a function that describes a relationship between two quantities.

## Objectives

### Students will be able to:

• Use the Design Recipe to identify dependent variables, independent variables, and constants.

Heads Up! Please make a copy of any documents you plan to share with students.

## Vocabulary

• Constant - A fixed number in a relationship.
• Dependent Variable - A value that changes based on an independent variable.
• Design Recipe - A systematic sequence of steps to document, test, and write functions.
• Independent Variable - An input variable the is controlled by the user.
• Purpose Statement - A brief description of what a function does.

# Teaching Guide

## Getting Started

### What is the Design Recipe?

The Design Recipe is a roadmap for defining functions, which programmers use to make sure the code they write does what they want it to do. Each step builds on the last, so any mistakes can be caught early in the process. This roadmap has a series of steps:

1. Write a Contract that describes the word problem. 1a. Write a Purpose Statement that breaks down the problem to isolate the function.
2. Write Examples based on the contract.
3. Define a function that matches the examples.

Let's start out by applying the Design Recipe together to the following problem:

Define a function `purple-star`, that takes in the size of the star and produces an outlined, purple star of the given size.

### Step 1 - The Contract

purple-star: Number -> Image

Be sure to include a good Name for each function, and remember that the Domain and Range can only include types like Numbers, Images, Strings, etc.

A Contract is the foundation for a function, which gives programmers just enough information to use it: the name of the function, the type (or types) of data it expects and the type of data it returns.

The Purpose Statement gives students insight into what the function should do in the Example step.

Stop here and analyze student Purpose Statements for depth of understanding. At this step, it is critical for students to have a strong understanding of what the function should do even if they cannot figure which function they need to use.

### Step 2 - Examples

• Every Example begins with the name of the function. Where could you find the name of the function? (from the Contract)
• Every Example has to include sample inputs. Where could you find out how many inputs this function needs, and what types they are? (from the Contract)
• Every Example has to include an expression for what the function should do when given an input. Where could you look to find out what this function does? (from the Purpose Statement)

Once you have two or more Examples, it should be easy to identify what has changed between them by going word by word and circle what changes. In fact, the number of things that change should match the number of things in the function’s Domain: if the Domain has a Number and a String in it, then those two values should be the things that differ between your Examples.

Be sure to label the circled change as a variable that makes sense to this problem before moving on to the Definition.

### Step 3 - Function Definition

By identifying what has changed between these Examples, we can define our actual function.

Remember that the Contract and Purpose Statement can be used to write the Examples, even if a programmer isn’t sure how to begin. Then the Examples are used to build the function even if the programmer isn't sure what to do.

## Activity

### Design Recipe Battle

In this activity students in pairs will analyze the Design Recipe to work through the following problems

Students will be expected to defend every action they took on the Design Recipe using evidence only from the previous section.

### Large Group Battle

As a class you will need to model how battling works. Through your Document Camera, Projector, or just on the board, have a student complete a blank Design Recipe one section at a time.

• Give the student 2 minutes to complete the Contract and Purpose Statement.
• For one minute question every aspect of the Contract and Purpose statement. Be as specific as possible. They have to be able to answer your questions using only the description or word problem of the original problem.
• Example: Where did you get the function-name from? Where did you get Number for the Domain? How did you know Number was supposed to be the Range? Where did you get the function in your purpose statement?
• Have the student cover up the description or word problem where the original problem came from. Now they must create their examples only using the Contract and Purpose Statement.
• Give 2 minutes for student complete both examples.
• For one minute question every aspect of the examples. Be as specific as possible.

• Example: Where did you get your function-name? Why did you choose ## as your input? How did you get your output? Did you do the work or did the computer do the work to find the output? Why did you make your examples different? How will the computer know where the variable should go?
• Have the student cover up the Contract and Purpose Statement.

• Give the student 1 minute to Define the Function
• For 1 minute question every aspect of the definition. Be as specific as possible.

• Example: Where did you get the variable from? How does the computer know what to do with the input? How do you know this function will behave like you want it to?
• You have successfully Battled! Awesome!

To further incentivize students, you can print a list of questions and have students keep score of how many they correctly defend.

### Driver - Navigator Battle

Now that your students have seen the type of questions and intensity of questioning modeled by you, they are ready to battle each other.

It is helpful to give all the Drivers (partner A) one problem and give Navigators (partner B) a different problem.

Your main priority to keep the energy high and time. The students will do the rest:

• 2 minutes to complete the Contract and Purpose Statement
• 1 minute (or 30 seconds depends on your class) for Driver to Battle (ask the questions)
• 1 minute (or 30 seconds depends on your class) for Navigator to Battle (ask the questions)

Have the class collectively take a breath, refocus and cover up the original problem

• 2 minutes to complete both Examples
• 1 minute (or 30 seconds depends on your class) for Driver to Battle (ask the questions)
• 1 minute (or 30 seconds depends on your class) for Navigator to Battle (ask the questions)

Have the class collectively take a breath, refocus and cover up the Contract and Purpose Statement.

• 2 minutes to Define the Function
• 1 minute (or 30 seconds depends on your class) for Driver to Battle (ask the questions)
• 1 minute (or 30 seconds depends on your class) for Navigator to Battle (ask the questions)

Important to note that students will have plenty of mistakes and they need to make revisions as they go through the battle. It is really helpful to battle 2 - 3 times on different problems and rotate partners on this day.

• Levels
• 1
• (click tabs to see student view)
View on Code Studio

## Standards Alignment

#### Common Core Math Standards

BF - Building Functions
• F.BF.1 - Write a function that describes a relationship between two quantities.
• F.BF.2 - Write arithmetic and geometric sequences both recursively and with an explicit formula, use them to model situations, and translate between the two forms.★
CED - Creating Equations
• A.CED.1 - Create equations and inequalities in one variable and use them to solve problems. Include equations arising from linear and quadratic functions, and simple rational and exponential functions.
• A.CED.2 - Create equations in two or more variables to represent relationships between quantities; graph equations on coordinate axes with labels and scales.
• A.CED.3 - Represent constraints by equations or inequalities, and by systems of equations and/or inequalities, and interpret solutions as viable or non- viable options in a modeling context. For example, represent inequalities describing nutritional and cost constr
• A.CED.4 - Rearrange formulas to highlight a quantity of interest, using the same reasoning as in solving equations. For example, rearrange Ohm’s law V = IR to highlight resistance R.
EE - Expressions And Equations
• 6.EE.9 - Use variables to represent two quantities in a real-world problem that change in relationship to one another; write an equation to express one quantity, thought of as the dependent variable, in terms of the other quantity, thought of as the independent va
• 7.EE.4 - Use variables to represent quantities in a real-world or mathematical problem, and construct simple equations and inequalities to solve problems by reasoning about the quantities.
F - Functions
• 8.F.1 - Understand that a function is a rule that assigns to each input exactly one output. The graph of a function is the set of ordered pairs consisting of an input and the corresponding output.1
• 8.F.2 - Compare properties of two functions each represented in a different way (algebraically, graphically, numerically in tables, or by verbal descriptions). For example, given a linear function represented by a table of values and a linear function represented
IF - Interpreting Functions
• F.IF.1 - Understand that a function from one set (called the domain) to another set (called the range) assigns to each element of the domain exactly one element of the range. If f is a function and x is an element of its domain, then f(x) denotes the output of f c
• F.IF.2 - Use function notation, evaluate functions for inputs in their domains, and interpret statements that use function notation in terms of a context.
• F.IF.3 - Recognize that sequences are functions, sometimes defined recursively, whose domain is a subset of the integers. For example, the Fibonacci sequence is defined recursively by f(0) = f(1) = 1, f(n+1) = f(n) + f(n-1) for n ≥ 1.
• F.IF.4 - For a function that models a relationship between two quantities, interpret key features of graphs and tables in terms of the quantities, and sketch graphs showing key features given a verbal description of the relationship. Key features include: intercep
• F.IF.5 - Relate the domain of a function to its graph and, where applicable, to the quantitative relationship it describes. For example, if the function h(n) gives the number of person-hours it takes to assemble n engines in a factory, then the positive integers w
• F.IF.6 - Calculate and interpret the average rate of change of a function (presented symbolically or as a table) over a specified interval. Estimate the rate of change from a graph.★
• F.IF.7 - Graph functions expressed symbolically and show key features of the graph, by hand in simple cases and using technology for more complicated cases.★
• F.IF.9 - Compare properties of two functions each represented in a different way (algebraically, graphically, numerically in tables, or by verbal descriptions). For example, given a graph of one quadratic function and an algebraic expression for another, say which
LE - Linear, Quadratic, And Exponential Models★
• F.LE.1 - Distinguish between situations that can be modeled with linear functions and with exponential functions.
• F.LE.2 - Construct linear and exponential functions, including arithmetic and geometric sequences, given a graph, a description of a relationship, or two input-output pairs (include reading these from a table).
MP - Math Practices
• MP.1 - Make sense of problems and persevere in solving them
• MP.2 - Reason abstractly and quantitatively
• MP.3 - Construct viable arguments and critique the reasoning of others
• MP.4 - Model with mathematics
• MP.5 - Use appropriate tools strategically
• MP.6 - Attend to precision
• MP.7 - Look for and make use of structure
• MP.8 - Look for and express regularity in repeated reasoning
NS - The Number System
• 6.NS.8 - Solve real-world and mathematical problems by graphing points in all four quadrants of the coordinate plane. Include use of coordinates and absolute value to find distances between points with the same first coordinate or the same second coordinate.
OA - Operations And Algebraic Thinking
• 5.OA.1 - Use parentheses, brackets, or braces in numerical expressions, and evaluate expressions with these symbols.
• 5.OA.2 - Write simple expressions that record calculations with numbers, and interpret numerical expressions without evaluating them. For example, express the calculation “add 8 and 7, then multiply by 2” as 2 × (8 + 7). Recognize that 3 × (18932 + 921) is three t
Q - Quantities
• N.Q.1 - Use units as a way to understand problems and to guide the solution of multi-step problems; choose and interpret units consistently in formulas; choose and interpret the scale and the origin in graphs and data displays.
• N.Q.2 - Define appropriate quantities for the purpose of descriptive modeling.