How to Help Students Fall in Love with Computer Science

The contrast between computer science in practice and computer science in class

Photo by Illán Riestra Nava on Unsplash

Every programmer is familiar with the catharsis of crafting an elegant solution to a problem. There is a unique feeling of reward that comes from inventing an algorithm with meaning and value. Unfortunately, students are being introduced to computer science without being introduced to this experience.

It’s not up to debate whether there is a problem with computer science education. Inside Higher Ed reports that nearly half of undergraduates in computer science, engineering, and math leave the field before completing degrees. From this group, computer science and information technology degrees suffer the worst retention rates.

The National Center for Women & Information Technology points out that women earn 57% of undergraduate degrees, but only 18% of degrees in computer science or information technology. “Irrelevant curriculum and reliance on lecturing instead of hands-on projects, teaching styles that discourage collaboration, lack of opportunities to take risks and make mistakes, and limited knowledge or inaccurate perceptions about computing careers” are cited as some of the reasons that women are discouraged from computer science.

At my university, where I’m a teaching assistant for the intro-level computer science course, I have observed these problems firsthand. Students are not exposed to the creative, personal, and community dimensions of the field. The experience for freshman computer science students is uninteresting, impersonal, confusing, and frustrating. The root of these problems is a bleak and ugly misrepresentation of the practice.

Appeal to creativity

The most significant failure in computer science education is the void of creativity. In school, assignments and exams evaluate a students’ ability to follow instructions and translate them into syntax. In practice, programming is a creative effort. There are no specific instructions, only well-defined problems. A programmer must invent a solution and design an implementation of the solution. This is the source of the feeling of reward that programmers fall in love with. But students are given no opportunity to invent or design.

Generally, an early programming assignment looks something like this:

public class P1 {
/*
* Declare a variable of type integer called myInt initialized to 10. Print the value of myInt.
* Declare a variable of type double called myDouble initialized to 2.0. Print the value of myDouble.
* Declare a variable of type String called myString initialized to "Hello!". Print the value of myString.
*/
public static void main(String[] args) {
// YOUR CODE HERE
}
}

There is no room for creative thinking. There is no meaning associated with myInt, myDouble, or myString to which the student can root his or her learning. There are instructions to follow, and syntactical rules to which the student must conform. Even worse, there are class and method declarations that the student is not expected nor able to understand. The student doesn’t learn anything, they just get confused. A better assignment would look like this:

/* 
You are tasked with defining the Pizza class. Declare three meaningful local variables of your choosing to represent a Pizza object. Implement a toString() method for the Pizza class that uses at least two of your variables.
*/
public class Pizza {

//declare variables here
    public String toString() {
//implement toString here
}
}

This assignment allows the student to relate the programming task to a real life idea that he or she is already comfortable with — pizza. The student is required to exercise creative thinking. She must ask, “What sort of information is important for the computer representation of a pizza?” She might determine that there should be a variable to represent the size of the pizza, the price, the style of crust, the number of pepperonis, whether the pizza is being offered at a special rate, how many slices it has, or any number of other attributes one could imagine might be manifested by a pizza. Many students will choose to create a variable to represent the size, but some would use an integer to describe the size in inches and others would use a character to represent the size as ‘S’, ‘M’, or ‘L’.

Then, the student must design the implementation of toString(). This requires creative thinking as well. What’s the best String representation of a Pizza object? The important thing is that it’s left up to the young programmer to decide.

The pizza assignment builds a deep and meaningful understanding of classes, objects, variables, and methods. After completing it, the student has designed her own personal implementation of the Pizza class. Of course, there’s a glaring downside to this style of assignment — it must be graded manually.

Photo by rawpixel on Unsplash

Make the experience personal

It’s too easy to have a computer grade assignments when the assignments are actually computer programs. The side effect of auto-grading is it makes computer science feel robotic and impersonal. In reality, programmers are interacting with each other — sharing code, algorithms, and ideas. Students need their code read, interpreted, and evaluated by a human. They need feedback on conventions and best practices. Most importantly, they need to get used to the idea that code is for humans.

The student will hand in his pizza assignment to be read and graded by a real person, and they will receive personal feedback. The grader might leave comments such as, “You chose to use an integer to represent the price. Don’t you think a double would make more sense?” or, “Make sure to adhere to camel case with variable names.”

This sort of interaction is very important. First of all, it forces the student to think critically about the representation or algorithmic decisions he makes while working. More importantly, it primes the student to have his code read and interpreted by other human beings.

Many students make the mistake that code is for the computer. This is a bit depressing and significantly misguided. If code was for the computer, we’d all be writing programs in assembly or even binary. Code exists to make our lives easier and more productive, and to allow for collaboration.

Photo by Kaleidico on Unsplash

Create a community that encourages collaboration

Computer science classes often isolate the young programmers. Assignments are to be done alone. Sharing code is not allowed. There is no peer instruction or review. At its best, this environment hinders social growth and negatively impacts careers. At its worst, this environment turns prospective students away from computer science.

After a semester in computer science, a student has written a narrative for the typical programming career. The programmer sits in room with a computer and no windows. Instructions are slipped in under the door. The programmer writes a program, and slips a response out. Of course, this couldn’t be farther from reality of a computer science career. But it is the reality of computer science classes. To fix this, students should be given group projects. This will force the students to put their heads together and make connections that aren’t possible in an isolated learning environment.

Furthermore, students should be tasked with peer-reviewing each other’s code. This motivates critical thinking about the most effective and reasonable implementations. If a student A’s solution is so convoluted that student B is not able to understand what student A was trying to do, student A probably doesn’t understand what’s going on. Student B can provide insight into the problem and help student A make connections that she was not making on her own. This has the added benefit of forcing students to become proficient at reading code, which is at least 50% of a programmer’s job.

Rethinking computer science

This is starting to sound more like an english class than a computer science class. Style? Red pen? Peer review? Reading?

English classes are more creative, personal, and collaborative — and english undergraduates are predominantly women. If retention rates in computer science are to be improved, we are going to have to rethink computer science education.