Teaching Functions to 5th Grade

I introduced functions to my 5th graders today. They are able to use them perfectly in the course F lessons for functions, but they are not understanding how or why they would be used outside of this context.

Any suggestions?

I like to talk to them about procedures in my classroom. In the beginning of the school year I have to tell the students to login in to Code.org by going to the website, entering the username, entering the password. Later in the year I just say (or Call the function) Login to Code.org!

Or all the steps to signing out of the computer and getting ready to leave the classroom. Most procedures you have a list of steps and you give them a name and they you are able to call on them at any time.

Hope this helps!

Motivating it from the perspective of software reuse might be a good hook. Perhaps explain that the same functionality may be needed in many parts of a program. Rather than repeating the same code in each place, a function can be created that can contains the code to perform the needed action and has a name that can be called in many other places of the program (see the Songwriting lesson). Rather than copying multiple lines of code in many places, all that is needed is to call the name of the function (block). Explain that software developers often use reusable libraries of functions rather than reinventing the wheel and copying the same code over and over again.

A deeper discussion could motivate the idea of procedural abstraction, and what are the essential things that a function (block) needs to accomplish its task (e.g., the “move” block needs to know the number of pixels, and the “turn” block needs to know the number of degrees.

1 Like

I can think of a number of reasons to use functions (procedures) This allows you to make scripts that have a single or simple function which are more easily understood, debugged and also can be reused again.

It is nice to be able to create single function scripts, test them to make sure they are working the way you want and then to reuse them with confidence. It is also easier to document a single function script and share it with others. This is particularly nice way to go for collaborative projects.

My final reason and for me the most important one is that as students (and adults) begin to write larger and more complicated programs it is nice to be able to create functions and then combine them into larger programs. Seymour Papert (MIT) would have called these mind-sized bites. It helps with organization. If you build and understand the parts, you can use them to create something more elaborate. It helps cuts through the complication. I hope this helps.

I suggest using a restaraunt menu. The regular meals and items are functions. Made the same way each time they are ordered, but special orders can be made using the function and adjusting the ingredients slightly. This allows for faster programming and reduced mistakes, while creating larger, more complex programs.

2 Likes

Seems like the answer to your question about functions should be built into the lessons. “Start with Why” Simon Sinek explains why. And Seymour Papert … Good question and please share your solution that help your students get it.

Maybe viewing a few of the different function videos would help them see how and why we use them -
Brina explains funcitons - https://www.youtube.com/watch?v=Esp1kkKFpg0

Chris Bosh - https://www.youtube.com/watch?v=8T5acEwfJbw

Bill Gates - https://www.youtube.com/watch?v=EoUnJB_BVLc&feature=youtu.be

Benefits of a function:
Once you have written a procedure or function that you know works as intended, you can call the function as often as you wish without worrying about the details or problems you had to solve to get it working.

And in defining a function to perform a certain task, you have essentially increased the capabilities of the programming language and can now use that function on its own or as part of even more complex actions.

By referencing a large and complex block of code by a single name it makes it much easier to understand what a program is doing by reading the code, and also easier to locate and fix problems or errors.

1 Like

Curious, with all the great answers, did your students get how and why functions are used outside the context? What helped most in clearing up their understanding? If asked on a test question, would love to hear what they wrote. Thanks for sharing.

I ended up using logging into code.org as an example. At the beginning of the year I had to give them each step, but now I can just say log-in.
I also used a song to help them understand why a function would be used. I printed the lyrics to a popular song where the chorus was written out the first time it is sung, and then as it is repeated I just typed the word chorus between each verse. I played the song for the students and they followed along with the printed lyrics. They were able to explain why I had written “chorus” between each verse.

1 Like