A learn-by-doing approach to coding

Katherine Young (center), a sophomore enrolled in 6.S04 (Fundamentals of Programming), works with Professor Srini Devadas on one of the class's software labs. Photo: Audrey Resutek

Computer science and engineering, a.k.a. CS or Course 6-3, was the most heavily enrolled major at MIT in the 2015-2016 academic year, with 594 undergraduates. The major has grown rapidly over the last several years, and with this growth CS faculty noticed students were starting out with a range of programming experience.

Some students entering the major already had experience as programmers, whereas many others were underprepared for introductory classes, says Srini Devadas, the Edwin Sibley Webster Professor of Electrical Engineering and Computer Science. CS faculty recognized that it was time to give students a solid foundation in programming. In response, they have developed 6.S04 (Fundamentals of Programming), a new course focused exclusively on programming ability.

“The teaching staff collectively saw an opportunity to improve the entire curriculum by addressing the programming ability gap early and thoroughly,” said Ilia Lebedev, a CS PhD candidate and head teaching assistant.

The new class was developed by Lebedev, Devadas and Associate Professor of Electrical Engineering and Computer Science Adam Chlipala. The class was piloted in the Fall 2015 semester with 42 students, and has an enrollment of 106 this semester. A cornerstone of the Department of Electrical Engineering and Computer Science's (EECS) updated curriculum, the class will be renumbered 6.009 when new undergraduate degree requirements take effect in Fall 2016.

The class is part of a series of subjects designed to step students from one level to the next in an unbroken staircase. One of the beginning classes, 6.01, is being redesigned to focus more on the basics of programming than previously, and is designed to accommodate students with arbitrary backgrounds, said Chlipala. Students with no programming background can alternately take 6.0001, an established class that teaches rudimentary programming, to prepare for 6.S04, which in turn will better prepare students for higher-level coursework.

Introductory-level computer science courses in general are under pressure to teach students skills they can use immediately, such as Java, to help them land internships. This can be at odds with the mission of laying a strong foundation for learning computer science, said Lebedev. “We compromised by teaching the class in Python, a popular language used all over, and focusing on developing the students’ programming and problem-solving skills, which will help them get more out of the curriculum,” he said.

Function over form

Software has many dimensions of quality: performance, algorithm and data structure choice, security, usability, clarity and maintainability, decoupling, and interface design, said Rob Miller, professor of electrical engineering and EECS education co-officer. “But the very first step is being able to write something that actually works and does what it’s supposed to, functionally,” he said. “That’s what 6.S04 focuses on.”

The defining principle of 6.S04 is to write a lot of code. “This class is about blank-slate programming,” said Devadas. “Given a specification, write an implementation. We think of it as a gym class,” he said. “You jump in and you do stuff. We think of ourselves as being the trainers and the laboratories are training exercises.”

The course teaches students good principles of design indirectly by giving them good examples. Students aren’t assessed on the readability or performance of their code. Grading is based on whether the program gives the right output for particular inputs. “If your code is way too verbose and cluttered, chances are it’s not going to work properly,” said Devadas.

The core of the coursework in 6.S04 is weekly labs. Each assignment requires students to write a functioning program, one that does something the students might find interesting. The lab assignments this semester are:

a Pandora-like music service;

an image filter;

a degrees-of-separation mapping;

a real-time physics simulation;

a solution to a tent packing problem;

path collecting the maximum number of coins on a grid;

a text auto completer;

a route planner that avoids left turns;

a variation of the board game Clue;

and a variation of the arcade game Breakout.

Students learn a particular programming concept in the once-a-week lecture and then apply the concept in that week’s lab. The programming concepts include distance functions, matrix transforms, loops and control flow, recursive search, trees and linked data structures, and hybrid data structures. The labs are designed to produce programs with well-defined behavior that can be unambiguously assessed as working or not. Lebedev built a user interface for the course based on the Chrome browser so the students can see their programs working, which helps them to debug. The only software required for the course is Python 2.7 and Chrome, which means the students can work offline and with any operating system they choose.

Auto grading

The instructors have developed an elaborate auto grader to evaluate the student’s work. The auto grader decouples evaluation from instruction. The result is the auto grader becomes a well-quantified challenge for the students to overcome and the instructors are free to be the friendly 6.S04 staff, said Lebedev. “This allows us much greater access to help them when they struggle,” he said.

EECS expects as many as 700 students to take the class each year, once it becomes a required course. One reason for the large enrollment is the class will be required for the forthcoming computer science minor, slated to begin in the fall. “6.S04 is well-positioned to become the definitive ‘this class makes you a programmer’ course, allowing other coursework to craft a more focused, more effective syllabus,” said Lebedev.