NOTE: As of December, site content associated with Google accounts has been blocked by the DCPS Technology system. For that reason, more up-to-date information can be found in my TEAMS channels for the remainder of the school year.
Warm Up (5 minutes)
Activity (30 minutes)
Wrap Up (10 minutes)
Parameter: a variable in a function definition. Used as a placeholder for values that will be passed through the function.
Argument: the value passed to the parameter
Return: used to return the flow of control to the point where the procedure (also known as a function) was called and to return the value of expression.
Return Total:
It stops the flow of the function. If a return is inside of a conditional, if that condition is met the function ends there.
It returns a value to the place where the function was called.
Extracting shared features to generalize functionality is known as procedural abstraction.
Using parameters allows the functions (also called procedures) to be generalized.
Using procedural abstraction helps improve code readability.
Procedural abstraction manages complexity by allowing for code reuse.
For example: the function move(id, direction) could be used to move an element in any direction, rather than writing separate functions for each direction.
In this lesson students work with partners to investigate two different apps that use parameters and return values. Students are also introduced to the mod operator as part of one of the apps that they use.
As with all Investigate lessons, this is an opportunity for students to dig into programs that use a new concept, in this case parameters and return, in the context of working apps. Encourage students to read the code carefully, discuss their findings with classmates, make connections to the Explore activity from the day before, and start making simple modifications to the program. Students will not leave this lesson as experts in writing programs with parameters and return, but they should understand the high level context and know they can refer back to the code in these investigate projects when they need help getting unstuck in the coming Practice and Make lessons.
CSP Conceptual Framework
AAP-2 - The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.
AAP-2.C - Evaluate expressions that use arithmetic operators.
AAP-3 - Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing programmers to write programs more quickly and with more confidence.
qAAP-3.B - For procedure calls: a. Write statements to call procedures. b. Determine the result or effect of a procedure call.
CSTA K-12 Computer Science Standards (2017)
AP - Algorithms & Programming
2-AP-14 - Create procedures with parameters to organize code and make it easier to reuse.
3B-AP-23 - Evaluate key qualities of a program through a process such as a code review.