LESSON OBJECTIVES Students will be able to Create
LESSON OBJECTIVES Students will be able to: ● Create and use functions for blocks of code that perform a single high-level task within a program ● Create and use functions to remove repeated blocks of code from their programs ● Create and use functions to improve the readability of their programs ● Explain how abstractions allow programmers to reason about a program at a higher level
Warm Up Imagine you needed to write a 5 -step set of instructions for going through your morning-from the time you wake up until you get to school. What would they be? Write down your steps in your journal and be ready to share.
This set of instructions is pretty easy to follow and understand. They're at the level you might think about when describing your day to a friend. Now let's go a level deeper. Pick one of your 5 steps and split it into 5 smaller steps you need to complete that larger task. Be ready to share your ideas again.
This is getting interesting. It seems like the first time we gave our steps we were "hiding" some of the details necessary to complete the task. Let's try this once more. Take one of your 5 smaller steps and split it up again into 5 even smaller steps.
Imagine we had split every one of your first 5 steps into 5, and then split all of those steps again. This would mean we would have a high level set of instructions, and at the bottom a really low-level or detailed set of instructions. Be ready to respond to the following questions. When would the high level set of steps you just wrote be most appropriate? When would the lowest level set of steps be most appropriate? Which one is easiest to reason about or understand?
Sometimes details are important, but often high level steps are much easier to reason about and make it clear what's happening. In programs the same thing is true. We've learned that blocks like velocity. X or is. Touching actually just contain code that we could've written ourselves. Using these commands, or abstractions, is really helpful since we can think about code at a high level. Today we're going to learn how to group lots of commands to create a single new block our own. In programming when we create a new block like this we call it a function.
NEW WORD! Function A piece of code that you can easily call over and over again.
You will be working with your clock partner Go to Code Studio Complete Unit 3, Chapter 2, Lesson 19
WRAP-UP Why would we say that functions allow us to "create our own blocks? " Why is this something we'd want to do?
In Your Journal Write down your own definition of an abstraction? Why would a function count as an abstraction?
Functions are a useful tool for helping us write and organize more complex pieces of code. As we start looking to the end of the unit and your final project, being able to keep your code organized will be an important skills.
- Slides: 12