Stupid gender stereotyping and questionable coding practices 101

The WSJ blog of all places has an article about how men and women code (and women do it better).

Apparently, "testosterone-fueled" men tend to write cryptic code without comments, while "touchy-feely and considerate" women tend to write lots of helpful comments and are just all-around nice people.

If you're going to make sweeping generalizations about how men and women code, I want to see some real studies, not the personal observations of some random female engineer.

The random engineer in question is Emma McGrattan, a high-up muckety-muck about Silicon Valley and the sole source quoted in the article, who

…boasts that 70% to 80% of the time, she can look at a chunk of computer code and tell if it was written by a man or a woman.

But that's not very impressive. 80% of the programmers at her company are men — she could guess "man" every time and have an 80% chance of being right. The ratio of men to women is even higher in the general programmer population (in the English speaking world, at least). So this means that the accuracy of her spidey senses is less than or equal to chance.

Even granting the premise that women add more comments to their code than men, I have my doubts about whether copious commenting is particularly helpful or even a good idea. That's why I'm not especially enthusiastic about her company's coding standards:

In an effort to make Ingres’s computer code more user-friendly and gender-neutral, McGrattan helped institute new coding standards at the company. They require programmers to include a detailed set of comments before each block of code explaining what the piece of code does and why; developers also must supply a detailed history of any changes they have made to the code. The rules apply to both Ingres employees and members of the open-source community who contribute code to Ingres’s products.

Spot the logical error corner

So, she created gender-neutral coding standards by enforcing the coding style that

she thinks women prefer?

A detailed history of any changes they have made? In the comments? Isn't that what source control is for? Please don't tell me that this major company has replaced its source-control system with code comments. The alternative is that this standard breaks the DRY principle (don't repeat yourself) by duplicating source-control information in the comments.

That's not the only problem with this standard. The big problem with comments is that they lie. Code, on the other hand, never lies. It does what it says it does (albeit sometimes cryptically). It's very common for programmers to modify the code without bothering to modify the comments; the comments, therefore, get out of date.

It's much better, in my opinion, to document code in a way that can never get out of date: with unit tests. I know it's a cliché, but I believe that comments should tell you the why, and unit tests should tell you the what and the how of the code.

At any rate, this article still gave me a warm fuzzy because the draconian standards imposed by Emma give lie to the depressing stereotypes that the article espouses.