Teaching Functions

Fabio Vinicius Binder
Teaching Programming Ideas
2 min readApr 8, 2019

Functions are somewhat like daily activities, they have names and a set of instructions that define them, like brush your teeth, cook a meal, etc. When we need to talk about such activities we only use their names because it is easier than repeating all the instructions every time. Everyone knows about this process, it is a great common ground to start talking about functions to new programming learners.

The swift language has a lot of functions, so it is a good idea to begin to teach this subject by showing the students some useful functions in order to motivate and give them food for thought. Functions are taught after variables, constants, and operations so the students already have some basic understanding of numbers, booleans, and strings. Of course, a teacher may resort to math functions because every student knows about them, but I think there are other useful functions that may be more interesting to the students.

How about using something very popular among students, like memes? For instance, take the young guy (Aaron Bailey) that makes a really funny face:

In Brazil there is a popular meme related to this image that mocks someone by repeating what was said (usually something annoying) but changing every vowel with an “i”, for instance: “It’s always in the last place you look” would became “It’s ilwiys in thi list plici yii liik”. So, why not teach the students to make a generator for this meme? It does not involve conditionals or loops, only variables and a function, like this:

Of course there are some caveats, like the student not understanding the sintax: object dot function. But I don’t consider it a critical problem because the exact meaning is not imporant right here, the teacher may explain it intuitively now and only give the exact meaning when the time is right, usually in the classes and objects topic.

In the next post I will talk about an idea to explain the creation of your own functions to tell a story.

--

--