• The Old New Thing

    Why are there two copies of Notepad?

    • 85 Comments

    You may have noticed that there's a copy of Notepad in %windir%\notepad.exe and another in %windir%\system32\notepad.exe. Why two?

    Compatibility, of course.

    Windows 3.0 put Notepad in the Windows directory. Windows NT put it in the System32 directory.

    Notepad is perhaps the most commonly hardcoded program in Windows. many Setup programs use it to view the Readme file, and you can use your imagination to come up with other places where a program or batch file or printed instructions will hard-code the path to Notepad.

    In order to be compatible with programs designed for Windows 95, there needs to be a copy of Notepad in the Windows directory. And in order to be compatible with programs designed for Windows NT, there also needs to be a copy in the System32 directory.

    And now that Notepad exists in both places, new programs have a choice of Notepads, and since there is no clear winner, half of them will choose the one in the Windows directory and half will choose the one in the System32 directory, thereby ensuring the continued existence of two copies of Notepad for years to come.

  • The Old New Thing

    The Date/Time control panel is not a calendar

    • 85 Comments

    Although many people use the Date/Time control panel to flip through a calendar, that's not what it is for. In fact, if you use it that way, you can create all sorts of havoc!

    In its original incarnation in Windows 95, the Date/Time control panel changed your date and time. If you clicked through the calendar to see next month, you actually changed your system clock to next month. If you changed your mind and clicked "Cancel", the Date/Time control panel undid its changes and restored the date to the original date.

    In other words, here's what happened, step by step:

    • On April 1, you open the Date/Time control panel.
    • You change the month to May. The Date/Time control panel changes your system date to May 1. If you are running an appointment calendar program, all appointments from the month of April will fire. (For example, your April 15th alarm to remind you to file your income taxes.) You are annoyed by all these alerts and you cancel them.
    • You decide you didn't want to change the month to May after all and click Cancel.
    • The Date/Time control panel changes the date back to April 1.
    • On April 15th, your income tax alarm fails to fire because you cancelled it, remember?

    In other words, the Date/Time control panel was not designed for letting you flip through a calendar. It was designed for changing the system date and time.

    Unaware of its design, people have been using the Date/Time control panel as if it were a calendar, not realizing that it was doing all sorts of scary things behind the scenes. It's like using a cash register as an adding machine. Sure, it does a great job of adding numbers together, but you're also messing up the accounting back at the main office!

    For Windows 2000, in reluctant recognition of the way people had been mis-using the Date/Time control panel, it was rewritten so that it doesn't change the system time until you hit the Apply button.

    Aaron Margosis shows you how to grant a user permission to change the system date and time without having to make them a full administrator.

  • The Old New Thing

    Google is the cute two-year-old girl with curly blond hair that gets all the attention

    • 85 Comments

    Let's see, Google Maps adds the world outside the United States, Canada and the UK, and people go ga-ga. Nevermind that Google's new "maps" have nothing beyond country boundaries. "Aww, look at Google, she's so cute and adorable!"

    I'm sure the people at the existing online map services like MapQuest and MSN MapPoint are sitting there like older siblings, wondering when exactly they turned into chopped liver. MSN MapPoint has actual maps of most of Europe, and MapQuest's library of maps is larger still. (Kathmandu anyone?) Both sites provide documentation on how to link directly to them. Yet they don't get drooled over.

    Somebody at MapQuest should take out a full page ad that goes something like this:

    Dear Google Maps,

    Welcome to the rest of the world! If you ever need driving directions, don't hesitate to ask.

    Love ever,
    MapQuest

  • The Old New Thing

    Solving one problem by creating a bigger problem

    • 84 Comments

    Often, people will not even realize that their solution to a problem merely replaces it with another problem. The quip attributed to Jamie Zawinski captures the sentiment:

    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.

    For example, in response to "How do I write a batch file that..." some people will say, "First, install <perl|bash|monad|...>". This doesn't actually solve the problem; it merely replaces it with a different problem.

    In particular, if the solution begins with "First, install..." you've pretty much lost out of the gate. Solving a five-minute problem by taking a half hour to download and install a program is a net loss. In a corporate environment, adding a program to a deployment is extraordinarily expensive. You have to work with your company's legal team to make sure the licensing terms for the new program are acceptable and do not create undue risk from a legal standpoint. What is your plan of action if the new program stops working, and your company starts losing tens of thousands of dollars a day? You have to do interoperability testing to make sure the new program doesn't conflict with the other programs in the deployment. (In the non-corporate case, you still run the risk that the new program will conflict with one of your existing programs.)

    Second, many of these "solutions" require that you abandon your partial solution so far and rewrite it in the new model. If you've invested years in tweaking a batch file and you just need one more thing to get that new feature working, and somebody says, "Oh, what you need to do is throw away you batch file and start over in this new language," you're unlikely to take up that suggestion.

    So be careful when you suggest a solution that has a high activation energy. Sure, something could be taken care of by a one-line perl script, but getting perl onto the machine is hardly a one-line endeavor.

  • The Old New Thing

    Cleaner, more elegant, and wrong

    • 84 Comments

    Just because you can't see the error path doesn't mean it doesn't exist.

    Here's a snippet from a book on C# programming, taken from the chapter on how great exceptions are.

    try {
      AccessDatabase accessDb = new AccessDatabase();
      accessDb.GenerateDatabase();
    } catch (Exception e) {
      // Inspect caught exception
    }
    
    public void GenerateDatabase()
    {
      CreatePhysicalDatabase();
      CreateTables();
      CreateIndexes();
    }
    
    Notice how much cleaner and more elegant [this] solution is.

    Cleaner, more elegant, and wrong.

    Suppose an exception is thrown during CreateIndexes(). The GenerateDatabase() function doesn't catch it, so the error is thrown back out to the caller, where it is caught.

    But when the exception left GenerateDatabase(), important information was lost: The state of the database creation. The code that catches the exception doesn't know which step in database creation failed. Does it need to delete the indexes? Does it need to delete the tables? Does it need to delete the physical database? It doesn't know.

    So if there is a problem creating CreateIndexes(), you leak a physical database file and a table forever. (Since these are presumably files on disk, they hang around indefinitely.)

    Writing correct code in the exception-throwing model is in a sense harder than in an error-code model, since anything can fail, and you have to be ready for it. In an error-code model, it's obvious when you have to check for errors: When you get an error code. In an exception model, you just have to know that errors can occur anywhere.

    In other words, in an error-code model, it is obvious when somebody failed to handle an error: They didn't check the error code. But in an exception-throwing model, it is not obvious from looking at the code whether somebody handled the error, since the error is not explicit.

    Consider the following:

    Guy AddNewGuy(string name)
    {
     Guy guy = new Guy(name);
     AddToLeague(guy);
     guy.Team = ChooseRandomTeam();
     return guy;
    }
    

    This function creates a new Guy, adds him to the league, and assigns him to a team randomly. How can this be simpler?

    Remember: Every line is a possible error.

    What if an exception is thrown by "new Guy(name)"?

    Well, fortunately, we haven't yet started doing anything, so no harm done.

    What if an exception is thrown by "AddToLeague(guy)"?

    The "guy" we created will be abandoned, but the GC will clean that up.

    What if an exception is thrown by "guy.Team = ChooseRandomTeam()"?

    Uh-oh, now we're in trouble. We already added the guy to the league. If somebody catches this exception, they're going to find a guy in the league who doesn't belong to any team. If there's some code that walks through all the members of the league and uses the guy.Team member, they're going to take a NullReferenceException since guy.Team isn't initialized yet.

    When you're writing code, do you think about what the consequences of an exception would be if it were raised by each line of code? You have to do this if you intend to write correct code.

    Okay, so how to fix this? Reorder the operations.

    Guy AddNewGuy(string name)
    {
     Guy guy = new Guy(name);
     guy.Team = ChooseRandomTeam();
     AddToLeague(guy);
     return guy;
    }
    

    This seemingly insignificant change has a big effect on error recovery. By delaying the commitment of the data (adding the guy to the league), any exceptions taken during the construction of the guy do not have any lasting effect. All that happens is that a partly-constructed guy gets abandoned and eventually gets cleaned up by GC.

    General design principle: Don't commit data until they are ready.

    Of course, this example was rather simple since the steps in setting up the guy had no side-effects. If something went wrong during set-up, we could just abandon the guy and let the GC handle the cleanup.

    In the real world, things are a lot messier. Consider the following:

    Guy AddNewGuy(string name)
    {
     Guy guy = new Guy(name);
     guy.Team = ChooseRandomTeam();
     guy.Team.Add(guy);
     AddToLeague(guy);
     return guy;
    }
    

    This does the same thing as our corrected function, except that somebody decided that it would be more efficient if each team kept a list of members, so you have to add yourself to the team you intend to join. What consequences does this have on the function's correctness?

  • The Old New Thing

    At last you can turn off the USB 2.0 balloon

    • 84 Comments

    One of the more annoying messages in Windows XP¹ is the "This USB device can perform faster" balloon that appears whenever you plug in a USB 2.0-capable device into a USB 1.0 port. When I click on that balooon, I get a message that says, "Sorry, you don't have any USB 2.0 ports. You'll have to install one to be able to take full advantage of this device."²

    Yeah, that's really nice, but one of my machines is a laptop, so its USB ports can't be upgraded. And my desktop computer at the time had an older motherboard that predated USB 2.0. The really annoying part was that there was no way to turn off the balloon. "Yes, I know I inserted the device into a USB 1.0 port, but this computer doesn't have any USB 2.0 ports, so stop bugging me already."

    It actually got the point that I went out and bought a USB 2.0 adapter card just to shut up the stupid balloon.³

    Thank goodness that in Windows Vista, the USB folks realized how annoying it is to show a balloon that yells at you for something you can't do anything about, and they added a way to disable the pop-up.

    Nitpicker's Corner

    ¹Although this statement takes the grammatical form of a statement of fact, it is actually a statement of opinion. Other people may legitimately disagree with this opinion. Whether the message is in fact "one of the more annoying messages in Windows XP" is irrelevant to the story; the employment of this statement of opinion is rhetorical and serves a useful storytelling purpose, namely to serve as an interesting introduction and to establish a context for elaboration. It does not establish the official position of Microsoft Corporation regarding how annoying that message is.

    ²That is not literally what the message says, but the underlying meaning is comparable. The message text has been paraphrased for rhetorical purposes (to create a more informal tone) and for time-saving purposes (to save me the trouble of having to re-create the message and carefully transcribe the message word-for-word).

    ³Again, the use of the word "stupid" here is rhetorical, indicating my level of frustration and not attempting to establish the official Microsoft position on the intelligence of the balloon or the people responsible for it.

  • The Old New Thing

    Engineering is about tradeoffs: How hard will you work to save 68KB of disk space?

    • 84 Comments

    One of the recurring themes in the comments to my explanation of the historical reasons why there are two copies of Notepad was to use a hard link (or possibly a symbolic link) to save having to waste the disk space for two whole copies of Notepad. As I like to say, engineering is about tradeoffs. Let's look at the cost-benefit analysis.

    On the one hand: Install two copies of Notepad. Cost: 68KB of disk space.

    On the other hand: Use hard links or symbolic links. Cost: Add support for hard links or symbolic links to the FAT filesystem, to the operating system Setup program, to file formats such as the Windows Imaging Format, and to the various disk duplication systems that system builders (and corporate customers) use for deploying Windows to thousands of machines. Don't forget to count the cost for design and testing.

    Imagine you're the scheduling manager for the Setup team. Which of these two options do you choose? 68KB of disk space or doing all the work to support hard links during Setup and then waiting for all the existing customers to upgrade their tools to versions which support hard links—which could take several years. Are you going to be the one to have to stand up in the Ship Room and say, "We can't ship Windows because ten of our customers hasn't upgraded their deployment tools yet, and I have no idea how long we're going to have to wait until they do"?

    And for those commenters who said that Windows should just get rid of one of the copies, you'll be pleased to know that Windows Server 2008 got rid of the copy in the Windows directory. There is now only one copy¹ of Notepad, and it's the one in the system32 directory. It wasn't long after the product was released that I learned of a program that hard-coded the one that no longer exists; I wish the vendors good luck in getting a patch out quickly.

    Footnotes

    ¹Nitpickers not welcome here. There is only one copy remaining of the two under discussion.

  • The Old New Thing

    When visitors to the United States underestimate the size of the country

    • 84 Comments

    A friend of mine who is from Lebanon (but now lives in Seattle) invited his grandmother to come visit for the summer. When she arrived, he asked her, "Grandma, is there anywhere in particular you would like to visit?"

    His grandmother replied, "I'd like go to to Washington, DC."

    "Okay, Grandma. Let me buy some plane tickets."

    "No, let's drive."

    "You want to drive all the way to Washington, DC? Here, let me show you on a map how far away it is."

    Grandma replied, "Let's do it."

    My friend said, "Okay, Grandma, we're going on a road trip!" He got the rest of the family on board with the plan, packed up the car, and set out early one morning for their cross-country trip.

    By the end of the day, they had made it as far as Idaho, where they stopped for the night. I assume that they made plenty of stops along the way because (1) part of the point of a road trip is to enjoy the things along the way, and (2) Grandma.

    Grandma asked, "Is this Washington, DC?"

    "No, Grandma. Washington, DC is still very far away. Here, let me show you on the map where we are."

    Grandma was unconvinced. "If you'd only stop and ask for directions, we would have been there by now." Grandma was certain that the only reason they were driving all day was that her grandson was lost and stupidly driving in circles, and if he only had driven in the right direction, they'd be there by now.

    Grandma's reference for distance was Lebanon, which is a relatively small country. You can drive from the northern tip of the country to the southern tip in a day. The United States is a bit bigger than that.

    A related story was when my parents in New Jersey hosted some friends from Japan. The first excursion they took was to New York City, a convenient train ride away. For their second trip, they said, "How about today we drive to Chicago?"

    Third story.

    Please share any funny stories about geographic blindness in your home country.

    (This was supposed to be posted on Geography Awareness Week but I messed up.)

  • The Old New Thing

    Why did it take so long for Windows to support a taskbar on more than one monitor?

    • 83 Comments

    Mark wants to know why Windows has never supported having a taskbar on more than one monitor. (The question was asked before Windows 8 multi-monitor taskbar support became publically-known.)

    The feature has always been on the list, but it's a long list, and specifically the cost of designing, implementing, testing, performing usability tests, then redesigning the feature (because you will definitely need to redesign something as significant as this at least once) historically prevented it from escaping the minus-100-point deficit.

    Features do not exist in a vacuum, and decisions about features necessarily take into account the other features under consideration. For a feature to be adopted, it not only must be valuable enough in itself, but it almost must provide a better cost/benefit ratio than any other features under consideration. While the benefit of a multi-monitor taskbar is high, you have to scale it down by the percentage of users who would be able to take advantage of such a feature. I don't know the exact numbers, but I would hazard that fewer than ten percent of users use a multiple-monitor system on a regular basis, so any benefit would have to be ten times as great as the benefit of features that have broader use.

    On top of that, the development cost of a multiple-monitor taskbar is significantly higher than most other taskbar features. Just the compatibility constraints alone make you shudder. (Think about all the programs that do a Find­Window looking for the taskbar and assuming that there is only one.)

    What changed in Windows 8 that made a multiple-monitor taskbar a feature worth implementing? I don't know, but I can guess. First of all, the overall engineering budget for the taskbar may have been raised, so that more features from the list can make the cut. Or maybe the people in charge of the taskbar decided to go with their gut and ignore the numbers, implementing a feature specifically targetting the enthusiast community even though the work would not be justified if you went strictly by the cost/benefit analysis. By doing this, they ended up short-changing other features which were perhaps more worthy if you looked at the numbers.

    And then you'd be asking, "Why didn't you do feature Y? I mean, it would have been far more useful to far more people than the multiple-monitor taskbar."

    (Of course, now that I mentioned Windows 8, everybody will treat this as open season to post their complaints here.)

  • The Old New Thing

    The importance of error code backwards compatibility

    • 83 Comments

    I remember a bug report that came on in an old MS-DOS program (from a company that is still in business so don't ask me to identify them) that attempted to open the file "". That's the file with no name.

    This returned error 2 (file not found). But the program didn't check the error code and though that 2 was the file handle. It then began writing data to handle 2, which ended up going to the screen because handle 2 is the standard error handle, which by default goes to the screen.

    It so happened that this program wanted to print the message to the screen anyway.

    In other words, this program worked completely by accident.

    Due to various changes to the installable file system in Windows 95, the error code for attempting to open the null file changed from 2 (file not found) to 3 (path not found) as a side-effect.

    Watch what happens.

    The program tries to open the file "". Now it gets error 3 back. It mistakenly treats the 3 as a file handle and writes to it.

    What is handle 3?

    The standard MS-DOS file handles are as follows:

    handle name meaning
    0stdinstandard input
    1stdoutstandard output
    2stderrstandard error
    3stdauxstandard auxiliary (serial port)
    4stdprnstandard printer

    What happens when the program writes to handle 3?

    It tries to write to the serial port.

    Most computers don't have anything hooked up to the serial port. The write hangs.

    Result: Dead program.

    The file system folks had to tweak their parameter validation so they returned error 2 in this case.

Page 6 of 453 (4,525 items) «45678»