When Maria Klawe became president of Harvey Mudd College in 2006, she was dismayed — but not surprised — at how few women were majoring in computer science. A mathematician and computer scientist herself, she arrived at Harvey Mudd (the smallest of the five so-called Claremont Colleges) in the midst of a nationwide downturn for women in computer science. As recently as 1985, 37 percent of graduates in the field were women; by 2005 it was down to 22 percent, and sinking. And the situation at Mudd was even grimmer. Of the college’s 750 students, about a third were women (the figure is now closer to half), but for years the percentage of computer science graduates had been hovering around the single digits. How Dr. Klawe (pronounced KLAH-vay) and her faculty turned things around — this year, nearly 40 percent of Harvey Mudd’s computer science degrees will go to women — sheds light on a gender gap that elsewhere remains stubbornly resistant to changing times. Thanks in part to companies like Facebook, Yelp and Zynga and in part to cultural sensations like the movie “The Social Network,” coders are hip and computer science is hot. Departments across the nation are brimming with students. But those students are overwhelmingly male. In 2010, just 18.2 percent of undergraduates in the field were women, according to the National Center for Education Statistics — in spite of gains in chemistry, biomechanical engineering and other so-called STEM fields (the acronym stands for science, technology, engineering and mathematics). “It must be the unique area of science and technology where women have made negative progress,” said Nicholas Pippenger, a mathematics professor at Harvey Mudd, who is married to Dr. Klawe. Dr. Klawe and others say the underrepresentation of women in the field is detrimental in a larger sense. Computer science, they say, is as vital to propelling society forward in the digital era as mechanical engineering was in the industrial age. “If we’re not getting more women to be part of that, it’s just nuts,” Dr. Klawe said. At Mudd, she continued, “we’re graduating 20 female computer science majors a year, and every one of them is a gem.” In 2005, the year before Dr. Klawe arrived, a group of faculty members embarked on a full makeover of the introductory computer science course, a requirement at Mudd. Known as CS 5, the course focused on hard-core programming, appealing to a particular kind of student — young men, already seasoned programmers, who dominated the class. This only reinforced the women’s sense that computer science was for geeky know-it-alls. “Most of the female students were unwilling to go on in computer science because of the stereotypes they had grown up with,” said Zachary Dodds, a computer scientist at Mudd. “We realized we were helping perpetuate that by teaching such a standard course.” To reduce the intimidation factor, the course was divided into two sections — “gold,” for those with no prior experience, and “black” for everyone else. Java, a notoriously opaque programming language, was replaced by a more accessible language called Python. And the focus of the course changed to computational approaches to solving problems across science. “We realized that we needed to show students computer science is not all about programming,” said Ran Libeskind-Hadas, chairman of the department. “It has intellectual depth and connections to other disciplines.” Dr. Klawe supported the cause wholeheartedly, and provided money from the college for every female freshman to travel to the annual Grace Hopper conference, named after a pioneering programmer. The conference, where freshmen are surrounded by female role models, has inspired many a first-year “Mudder” to explore computer science more seriously.