Hacking at the Windows source code

Posted on February 19, 2004
Filed Under /dev/null/ | 122 views |

Disclaimer: Microsoft - I don’t have your source code. Keep the dogs at bay.

Over on k5 Selznak has written an entertaining article about the comments in the recently-leaked Windows 2000 source code: We Are Morons: a quick look at the Win2k source.

Like any massive project the Windows source has seen the hands of multiple developers, all working with and against each other’s code. Most of the comments reflect this, as well as the frustrations of dealing with computers (someday they’ll work properly every time, someday….). As a general rule of thumb swearing in your comments is to be frowned upon, as is insulting developers who’ve come before. That sort of thing will likely come back to bite you on the ass later.

But one section of the article is particularly interesting: the bit about hacks. According to Selznak the source has over 4000 references to the term hack:

private\inet\mshtml\src\core\cdbase\baseprop.cxx:
// HACK! HACK! HACK! (MohanB) In order to fix #64710 at this very late

private\inet\mshtml\src\site\layout\flowlyt.cxx:
// God, I hate this hack …

private\ntos\w32\ntuser\client\nt6\user.h:
* The magnitude of this hack compares favorably with that of the national debt.

Excellent stuff! These, unlike the other comments pointed out in the article, are not something Microsoft should be embarrassed about. These are not comments the developers should be chastized for. These are comments they should be lauded for and encouraged to write and in fact these comments should have more descriptive text about the hacks they precede.

Every developer hacks their code at one point or another. If we all had the time we’d spend weeks on each function until it’s tweaked to within an inch of it’s life. If we had the resources we’d track every bug back through the complete source, through each library, into other applications if need be, until we’d found the very root of the problem, fixed it, and propogated it back up the chain so we need not hack at all. But it rarely happens that way.

So sometimes we hack.

As a presenter at a conference once said many years ago: “Winning ugly is still winning.”

Hacks in code are only a problem if they’re not commented. Without comments they may be mistaken as best practice by the next developer to touch the codebase. Any good developer reading source code who comes across the phrase “This is a hack…” will immediately think “Maybe I can do that better” and probably try. They may even fix it. But if we don’t give them the pointer in the first place, they - or maybe ourselves months down the line - may never get the chance.

So I say: if you hack your code, be proud and comment it for all it’s worth. Note it, describe it, and then if you’ve got the time later, go back and kill it.

And to Microsoft’s Windows 200 developers: good job on that.

Comments

Comments are closed.