Teaching Functions as a Concept

In CSE 231, the professors recently introduced the concept of a function to students. Students then had to use the concept of functions in their weekly project to draw an American Flag in Turtle Graphics. We have used Turtle a couple of times before in the class, discussed in Introduction to Programming, Lab 2 and Turtle in Python.

In the previous lessons, Turtle has proved to be a very useful tool for students to visualize what a program is doing. It is also exciting and fun for them, encouraging creativity in programming.

I’m skeptical, however, about its use for our first project on functions. It required students to create at least four functions and use them to draw a flag:

draw_rectangle(length, height, color)
draw_star(size, color)

These functions were clear, contained functions that were not confusing at all to students, and they all did very well on the assignment:


The problem appeared instead in the next week’s project, when they had to use functions in a situation without Turtle. The task was to take an input file called riskfactors.csv, read in the data about health indicators for the 50 states for 20 different risks identified by the Center for Disease Control, store five specific values of these indicators for each state in lists, find the minimum and maximum values for each least, and finally create an output file called best_and_worst.txt which displayed the max and min values and states for the five specific indicators.

In contrast to the previous project, this problem set-up does not define clear functions that a programmer might want to create. It requires the student to divide the problem into a set of sub-problems to solve with functions – which is a skill that the students did not yet have.

As I’m grading their work, I’m seeing that a lot of students (about 30 percent) didn’t even submit a working program, which is very unusual. When asked what is most difficult about the project, they said “Everything.” and “I didn’t know how to start.” They weren’t seeing ways to parse the problem given to them and break it up.

So, what are we actually looking for in their code? We want them to isolate certain processes in functions. So, examples of functions we would have liked to see are:

#read in a file, storing the necessary values to lists

#finds the minimum value in the indicator_list
#do a reverse-lookup of the index in state_list
#return the min and the corresponding state
get_min(indicator_list, state_list)
#finds the maximum value in the indicator_list
#do a reverse-lookup of the index in state_list
#return the max and the corresponding state
get_max(indicator_list, state_list)
#write the best and worst values to an output file
#format the output file according to specifications

Now, the problem I’m seeing is that we are expecting students to know how to divide a problem into a set of functions. We teach them what functions are, but we don’t teach them how to break a problem into pieces, a necessary facet of being a successful programmer and computer scientist. In essence, we aren’t teaching when and how to apply the concept of a function – a problem addressed in this post about conceptual knowledge in engineering.

The solutions that students submitted either (a) had no functions or (b) had functions which didn’t make sense in context. For example, one student created a function specific to each indicator, which did all of the work of the four ideal functions listed above. That means he copied and pasted his code five times – once for each indicator function:

He then proceeded to create four identical functions, with the only change being in updating i in row[i]. Interestingly, he notes in the comments at the beginning of each of these repetitive functions “Used the same structure as above.”

So, the concept of functions isn’t translating to students in the way we would like to see. My project in EGR 811: Engineering Education addresses this disconnect in student problem-solving approaches, so if you’re interested in reading more about the research in algorithms education, see my posts about the project.


But, what does this mean for me as a TA now?

I need to (somehow) do a bit of patching up on student knowledge bases of breaking down a problem. I’m going to be looking into ways to help students learn the process for approaching a new problem, and I’m hoping to put together some short lesson modules for my lab section which may help.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s