The percentage of women studying computer science actually has fallen since the 1980s. Dr. Cheryan theorizes that this decline might be partly attributable to the rise of pop-culture portrayals of scientists as white or Asian male geeks in movies and TV shows like “Revenge of the Nerds” and “The Big Bang Theory.” The media’s intense focus on start-up culture and male geniuses such as Steve Jobs and Bill Gates might also have inspired more young men than women to enter the field.

Men sometimes scoff that if young women let such nebulous factors deter them from careers in physics or computer science, the women are exercising their own free choice, and if girls were tough enough, such exaggerated stereotypes and feelings of discomfort wouldn’t discourage them.

Yet I wonder how many young men would choose to major in computer science if they suspected they might need to carry out their coding while sitting in a pink cubicle decorated with posters of “Sex and the City,” with copies of Vogue and Cosmo scattered around the lunchroom. In fact, Dr. Cheryan’s research shows that young men tend not to major in English for the same reasons women don’t pick computer science: They compare their notions of who they are to their stereotypes of English majors and decide they won’t fit in.

All this meshes with my own experience. Even though I felt more comfortable wearing a T-shirt and jeans than a skirt and high heels, after four years of studying physics at Yale I felt so much pressure to dress and act like a man that I became extremely uncomfortable about my identity as a woman. I loved teaching myself to program the university’s new IBM mainframe. What a miracle it seemed that boxes of punched cardboard cards could produce pages and pages of a printed simulation of a collision between a K meson and a proton.

But the summer I worked as a programmer at Oak Ridge National Laboratory in Tennessee, I felt out of place among my mostly male colleagues because I hated drinking beer and didn’t like being mocked for reading novels. Not to mention that the men who controlled access to the computer made me listen to a barrage of sexist teasing if I wanted to be given that day’s code to run my program.

Despite my passion for physics, I didn’t feel what Dr. Cheryan calls “an ambient sense of belonging” and left science. As this new research demonstrates, young women today still are avoiding technical disciplines because, like me, they are afraid they won’t fit in.

To make computer science more attractive to women, we might help young women change how they think about themselves and what’s expected of them. But we might also diversify the images of scientists they see in the media, along with the décor in the classrooms and offices in which they might want to study or work.