Maintaining Notepad is not a full-time job, but it’s not an empty job either

Raymond Chen

Raymond

When I mentioned that one of my now-retired colleagues was responsible for maintaining Notepad, commenter Neil noted, “I can’t imagine theres much actual maintenance.”

You’d be surprised.

For one thing, Notepad is a common guinea pig. If a team is adding a new feature, they may ask Notepad to support the feature, in order to get some feedback on how well the feature works in a “real program”, rather than a unit test.

For example, did you know that you can type https://www.microsoft.com/ into Notepad’s File Open dialog?

Of the various improvements he made to Notepad, there are two that stand out in my memory.

First was the Status Bar. There is no obvious way to be notified when the caret moves within an edit control, but my colleague figured out a way: Notepad registers for its own object location change accessibility notifications. That way, it learns when the caret moves and can respond by updating the status bar with the caret’s current location.

Second was how he got Notepad to load files so quickly. When he took over ownership of Notepad, the program read the file into memory before handing it to the edit control. He kept finding little shortcuts to shave off some time here, offload some work there, and when he was done, Notepad had gotten completely out of the file-parsing business. To load a file, Notepad maps a view of the file as a memory-mapped file and uses that as the source. The code figures out the encoding, performs a code page conversion to UTF-16LE if necessary, puts the result in a memory block, and then uses the EM_SET­HANDLE message to hand that entire block to the edit control.

Notepad beats them all.

He was particularly proud of the fact that he improved the performance of loading a file into Notepad by deleting lots of code from the “Load a file” function.

Raymond Chen
Raymond Chen

Follow Raymond