麻豆淫院


Real-world programming in the classroom

Real-world programming in the classroom
Computer science professors Saman Amarasinghe, left, and Charles Leiserson co-teach a class called Performance Engineering of Software Systems, where students' code is reviewed by volunteer Boston-area programmers. Photo: Patrick Gillooly

In undergraduate computer-science classes, homework assignments are usually to write programs, and students are graded on whether the programs do what they're supposed to. Harried professors and teaching assistants can look over the students' code and flag a few common and obvious errors, but they rarely have the time coach the students on writing clear and concise code.

In the real world, however, code clarity is as important as . Large software projects can involve hundreds of , each working on a small corner of an application, and over the course of a project, personnel turnover can be high. Testing, revising and updating software may require people to review code that they had no hand in writing. If the code isn鈥檛 intelligible, engineers can waste a huge amount of time just figuring out how an existing program does what it does.

Professors of computer science Charles E. Leiserson and Saman Amarasinghe, who co-teach a class called Performance Engineering of Software Systems, believe that undergraduates should be taught to write clear code, not just running code. So this fall, for the second year in a row, in the class won鈥檛 just have their projects graded by their teaching assistants; they鈥檒l also have their code reviewed by senior programmers from the Boston area, who volunteer their time through a program that Amarasinghe and Leiserson call Masters in the Practice of Software Systems Engineering, or MITPOSSE.

The roughly 70 students in the class work on four major projects a semester, in two-person teams. After each project is submitted, students from separate teams are paired, and each pair meets with one of the professional programmers for a code review. The code review lasts between 60 and 90 minutes, and each of the 20-odd professionals meets with two pairs of students. The code reviews don鈥檛 count toward the students鈥 final grades, but they are mandatory.

The mother of invention

Leiserson and Amarasinghe introduced the class, which they teach only in the fall, three years ago. The first year, enrollment was lower than it is now, and the professors decided to hold their own half-hour code reviews with individual students after each project. 鈥淭hat killed us,鈥 Leiserson says. 鈥淓ven though we had a small class at the time, it was clearly not scalable.鈥 So in the summer of 2009, Amarasinghe and Leiserson put the word out among friends and colleagues, former students, and members of the Computer Science and Artificial Intelligence Laboratory鈥檚 Industry Affiliates Program that they were recruiting seasoned programmers to serve as mentors to their students in the fall. 鈥淲e got a tremendous response,鈥 Leiserson says. Indeed, in both 2009 and 2010, the professors had to turn away applicants to the program. To Amarasinghe and Leiserson鈥檚 knowledge, theirs is the first computer science class in the country to incorporate code review with professional software engineers.

According to Amarasinghe, the chief purpose of the MITPOSSE program is to help students develop their own programming styles. By 鈥渟tyle鈥 he means things like selecting names for variables, so that it鈥檚 clear to later readers what they refer to; avoiding the use of so-called 鈥渕agic numbers,鈥 numerals that are simply inserted into equations without explanation (the better practice, Amarasinghe explains, is to assign the number a name that indicates its purpose, and then use the name in subsequent equations); indenting lines of code; and, most important, adding comments 鈥 lines of text that appear next to the program code and explain what it鈥檚 doing, but which the computer ignores when converting code into an executable program.

In many computer-science classes, Amarasinghe says, professors trying to preserve intelligibility will insist on a particular style of coding, which may not be natural for some students and, he says, can actually lead to bad code. 鈥淭he way we look at programming, it鈥檚 like writing an English paper,鈥 he says. 鈥淚f you are in English class, there鈥檚 no set way of writing.鈥 What鈥檚 important is that a programmer鈥檚 style be consistent, not that it slavishly ape some model.

Less is more

Of course, all computer-science professors emphasize the importance of good comments, but busy students usually try to get their programs working and then stick in comments in whatever time they have left. Reid Kleckner, who took Amarasinghe and Leiserson鈥檚 class as an undergraduate last year and, as a master鈥檚 candidate, is a teaching assistant this year, says that the MITPOSSE reviews can help some students get a better grasp of the purpose of comments. 鈥淯sually, students hear, 鈥楥omment your code,鈥 and they say okay, line by line, 鈥楾his is what this line does, this is what this line does.鈥欌 But, Kleckner explains, comments are in fact more useful when they are spare and descriptive. A program might, for instance, include some clever but obscure procedure that makes it run more efficiently. Simply commenting in the margin that, say, the procedure rounds a number up to the nearest power of two may be all the information the reader needs. 鈥淵ou don鈥檛 need to say, here are the arithmetic operations that I am performing, and they achieve this result. Here鈥檚 my mathematical proof,鈥 Kleckner says.

Moreover, Kleckner says, with the MITPOSSE approach, 鈥淚t鈥檚 not just graduate students telling you how to write code. It鈥檚 coming from a figure of authority, in some sense.鈥 He laughs and adds, 鈥淣ot that the T.A. is not a figure authority.鈥 But a T.A. is not a prospective employer.

Indeed, for the mentors, some of the appeal of volunteering for the program may very well be the opportunity to scout talent. So Leiserson and Amarasinghe have drawn up a set of rules that the mentors agree to abide by, including 鈥渘o recruiting, hints at job opportunities, offers of summer internships, lab tours, free dinners, etc.,鈥 until 鈥渢he semester is over and no power relationship exists.鈥

But many of the mentors simply find the work intrinsically satisfying. Barry Perlman, who as an independent software consultant doesn鈥檛 have any job vacancies to fill, volunteered with the program last year and came back again this year. 鈥淚 felt like I was doing something useful,鈥 he says. 鈥淭he world doesn鈥檛 need more software engineers; the world needs better software engineers.鈥 Andrew Lamb, too, has joined the MITPOSSE for a second year in a row. He works for a small software company, and though he acknowledges that 鈥渋t鈥檚 nice to get that name out there,鈥 the company isn鈥檛 currently looking for any new hires. But, Lamb says, 鈥渨hen they have some question and I鈥檓 able to answer it, and their eyes light up, and they say, 鈥業 get it, I get it,鈥 that鈥檚 very cool.鈥


This story is republished courtesy of MIT News (), a popular site that covers news about MIT research, innovation and teaching.
Citation: Real-world programming in the classroom (2010, October 28) retrieved 8 May 2025 from /news/2010-10-real-world-classroom.html
This document is subject to copyright. Apart from any fair dealing for the purpose of private study or research, no part may be reproduced without the written permission. The content is provided for information purposes only.

Explore further

Consumer confidence hits five-year high in Michigan

0 shares

Feedback to editors