8_1_7
WHAT: Understand the purpose of sub-routines in programs
SMART Start:
Define the term "Array"
Extra Mile:
Modify this code so that it becomes an array:
name1="Sam"
name2="Paul"
name3="Becky"
name4="Katie"
HOW:
Activity 1 - READ
Think of something that you do every single day. I would hope that one of those things would be brushing your teeth!
Imagine if every time you brushed your teeth you had to learn how to do it. What would that be like?
There would be quite a few drawbacks of having to do this:
- You wouldn't know the quickest way
- You might not do it correctly
- You might complete the steps in the wrong order
- It would take you longer to think of the instructions
Your brain remembers your routine. You are probably on "auto-pilot" when you brush your teeth because you have your algorithm and just get it done.
This is a little bit like a sub-routine. A sub-routine is used to store instructions that are frequently needed. They have many benefits for programmers:
- Errors are easier to spot within the sub-routine
- Once an efficient sub-routine has been created it can be re-used any time
- Its faster to program because the programmer doesn't need to keep typing lines of code
- Its also faster to program because sub-routines may have been created for similar problems that can be easily re-used
It is important to note that sub-routines don't use less resources to run the application. Just like when you brush your teeth, you still use energy to carry out the routine.
Activity 2 - WATCH AND LISTEN
CHECK:
EMBED:
Write a sub-routine for an activity that you do quite a bit. The sub-routine should have the ability to be used by any human to perform the same task.
CLASSROOM IDEAS:
This outcome probably won't take very long for students to grasp. The next step is to learn how to create them in a programming language.
A nice activity would be to distribute "sub-routines" in the form of musical rhythms and get the class to complete a song by playing the various sub-routines in a defined order.