October, 2008

  • The Old New Thing

    An artist's conception of the new citizenship test


    Today is the first day of the controversial redesigned United States citizenship examination. For the next year, candidates who applied before today can choose whether they want to use the old test or the new one.

    To help prepare for the new examination, I propose the following warm-up, which I tested (with the assistance of another United States citizen) on a foreign national, a Canadian from British Columbia, so there should be no language barrier as long as we are careful to avoid the word about.

    1. What condiment applies to French-fried potatoes?
    2. Which fires a bigger bullet, a nine or a twenty-two?
    3. Does the metric system suck?
    4. How long is a football field? (Note: Answering in metric or confusing football with soccer are automatic disqualifications.)
    5. Define class action lawsuit.
    6. True or false: You have a God-given right to drink alcohol until you pass out.

    Here are the answers the Canadian gave, along with my response and additional commentary from my co-examiner in blue.

    1. What condiment applies to French-fried potatoes?
      Vinegar... no, mayonnaise... no wait, it's that red stuff.

      No credit for not being able to name the red stuff. Negative points for even thinking of the words vinegar or mayonnaise.
    2. Which fires a bigger bullet, a nine or a twenty-two?
      That's what the NRA's 1-800 number is for, when you need to know, right?

      No credit. Every American knows the hierarchy of firearms.

      Least all real Americans.

    3. Does the metric system suck?
      Gol-dang right (scratch)

    4. How long is a football field?
      328.08 feet

      Bzzzt. Americans don't use decimal points and feet in the same sentence. That's treading dangerously close to that heathen metric system.
    5. Define class action lawsuit.
      When more than one American at once abuses the legal system.

      Close. It's when one American abuses the legal system on behalf of all Americans.

      Unless I am doing it, in which case it isn't abuse.

    6. True or false: You have a God-given right to drink alcohol until you pass out.
      False, because no state law is allowed to refer to God, right?

      Incorrect. You are allowed to refer to God, despite what the ACLU says. Americans are endowed by their Creator with several inalienable rights. Among them are the rights to drink alcohol, discharge firearms, belch, swear, and make obscene gestures.

      You left out scratch and drive.

    [Raymond is currently away; this message was pre-recorded.]

  • The Old New Thing

    Why do maximized windows lose their title bar translucency?


    If you have translucent title bars enabled,¹ you may have noticed that the translucency goes away when you maximize a window. Why is that?

    This is a performance optimization.

    Opaque title bars are more efficient than translucent ones, and when you maximize a window, you're saying,² "I want to focus entirely on this window and no other windows really matter to me right now." In that case, the desktop window manager doesn't bother with translucency because you're not paying any attention to it anyway.

    This may seem like a very minor change, but the difference is noticeable on benchmarks, and, like it or not, magazine writers like to use benchmarks as an "objective" way of determining how good a product is. The reviewers choose the game, and we are forced to play it.


    ¹The desktop window composition feature that provides the translucent title bar probably has some official name, but I can never remember what it is and I'm too lazy to go find out.

    ²This may not be literally what you're saying, but it's how the window manager interprets your action.

    [Raymond is currently away; this message was pre-recorded.]

  • The Old New Thing

    Why does the Disk Management snap-in report my volume as Healthy when the drive is dying?


    Windows Vista displays a big scary dialog when the hard drive's on-board circuitry reports that the hardware is starting to fail. Yet if you go to the Disk Management snap-in, it reports that the drive is Healthy. What's up with that?

    The Disk Management snap-in is interested in the logical structure of the drive. Is the partition table consistent? Is there enough information in the volume to allow the operating system to mount it? It doesn't know about the drive's physical condition. In other words, "As far as the Disk Management snap-in is concerned, the drive is healthy."

    Similarly, your car's on-board GPS may tell you that you are on track for a 6pm arrival at your destination, unaware that you have an oil leak that is going to force you to the side of the road sooner or later. All the GPS cares about is that the car is travelling along the correct road.

    [Raymond is currently away; this message was pre-recorded.]

  • The Old New Thing

    Why can't you thunk between 32-bit and 64-bit Windows?


    It was possible to use generic thunks in 16-bit code to allow it to call into 32-bit code. Why can't we do the same thing to allow 32-bit code to call 64-bit code?

    It's the address space.

    Both 16-bit and 32-bit Windows lived in a 32-bit linear address space. The terms 16 and 32 refer to the size of the offset relative to the selector.

    Okay, I suspect most people haven't had to deal with selectors (and that's probably a good thing). In 16-bit Windows, addresses were specified in the form of a selector (often mistakenly called a "segment") and an offset. For example, a typical address might be 0x0123:0x4567. This means "The byte at offset 0x4567 relative to the selector 0x0123." Each selector had a corresponding entry in one of the descriptor tables which describes things like what type of selector it is (can it be used to read data? write data? execute code?), but what's important here is that it also contained a base address and a limit. For example, the entry for selector 0x0123 might say "0x0123 is a read-only data selector which begins at linear address 0x00524200 and has a limit of 0x7FFF." This means that the address 0x0123:n refers to the byte whose linear address is 0x00524200 + n, provided that n ≤ 0x7FFF.

    With the introduction of the 80386, the maximum limit for a selector was raised from 0xFFFF to 0xFFFFFFFF. (Accessing the bytes past 0xFFFF required a 32-bit offset, of course.) Now, if you were clever, you could say "Well, let me create a selector and set its base to 0x00000000 and its limit to 0xFFFFFFFF. With this selector, I can access the entire 32-bit linear address space. There's no need to chop it up into 64KB chunks like I had to back in the 16-bit days. And then I can just declare that all addresses will be in this form and nobody would have to bother specifying which selector to use since it is implied."

    And if you said this, then you invented the Win32 addressing scheme. It's not that there are no selectors; it's just that there is effectively only one selector, so there's no need to say it all the time.

    Now let's look at the consequences of this for thunking.

    First, notice that a full-sized 16-bit pointer and a 32-bit flat pointer are the same size. The value 0x0123:0x467 requires 32 bits, and wow, so too does a 32-bit pointer. This means that data structures containing pointers do not change size between their 16-bit and 32-bit counterparts. A very handy coincidence.

    Next, notice that the 16-bit address space is still fully capable of referring to every byte in the 32-bit address space, since they are both windows into the same underlying linear address space. It's just that the 16-bit address space can only see the underlying linear address space in windows of 64KB, whereas the 32-bit address space can see it all at once. This means that any memory that 32-bit code can access 16-bit code can also access. It's just more cumbersome from the 16-bit side since you have to build a temporary address window.

    Neither of these two observations holds true for 32-bit to 64-bit thunking. The size of the pointer has changed, which means that converting a 32-bit structure to a 64-bit structure and vice versa changes the size of the structure. And the 64-bit address space is four billion times larger than the 32-bit address space. If there is some memory in the 64-bit address space at offset 0x000006fb`01234567, 32-bit code will be unable to access it. It's not like you can build a temporary address window, because 32-bit flat code doesn't know about these temporary address windows; they abandoned selectors, remember?

    It's one thing when two people have two different words to describe the same thing. But if one party doesn't even have the capability of talking about that thing, translating between the two will be quite difficult indeed.

    P.S., like most things I state as "fact", this is just informed speculation.

  • The Old New Thing

    If you're going to reformat source code, please don't do anything else at the same time


    I spend a good amount of my time doing source code archaeology, and one thing that really muddles the historical record is people who start with a small source code change which turns into large-scale source code reformatting.

    I don't care how you format your source code. It's your source code. And your team might decide to change styles at some point. For example, your original style guide may have been designed for the classic version of the C language, and you want to switch to a style guide designed for C++ and its new // single-line comments. Your new style guide may choose to use spaces instead of tabs for indentation, or it may dictate that opening braces go on the next line rather than hanging out at the end of the previous line, or you may have a new convention for names of member variables. Maybe your XML style guidelines changed from using

    <element attribute1="value1" attribute2="value2" />

    Whatever your changes are, go nuts. All I ask is that you restrict them to "layout-only" check-ins. In other words, if you want to do some source code reformatting and change some code, please split it up into two check-ins, one that does the reformatting and the other that changes the code.

    Otherwise, I end up staring at a diff of 1500 changed lines of source code, 1498 of which are just reformatting, and 2 of which actually changed something. Finding those two lines is not fun.

    And the next time somebody is asked to do some code archaeology, say to determine exactly when a particular change in behavior occurred, or to give an assessment of how risky it would be to port a change, the person who is invited to undertake the investigation may not be me. It may very well be you.

  • The Old New Thing

    How can I increase the number of files I can open at a time?


    People who ask this question invariably under-specify the question. They just say, "How can I increase the number of files I can open at a time?" without saying how they're opening them. From the operating system's point of view, the number of files you can open at a time is limited only by available resources. Call CreateFile until you drop. (This remark applies to local files. When you talk over the network, things get weirder.)

    The fact that these people are asking the question, however, indicates that they're not using CreateFile to open the files. They're using some other intermediate layer, and it's that layer that is imposing some sort of limit. You'll have to investigate that layer to see what you can do about raising the limit.

    [Raymond is currently away; this message was pre-recorded.]

  • The Old New Thing

    Strange things happen when you let people choose their own name, part 1


    One of the things that happens when you arrive at Microsoft is you are assigned an email account, and the name of that account becomes your identity. The IT department has a set of rules which they follow to arrive at your account name, but you can petition for reconsideration if the result of their algorithm produces something you don't like.

    You have more flexibility with your display name. For example, you may commonly go by a less formal version of your legal name, or you may go by your middle name or your initials or you may choose to adopt an English name as your professional name. But even though you have flexibility here, you don't have total freedom. I doubt that a request for my name to show up in the address book as Raymond Luxury-Yacht would be approved.

    There is a third component to your name, however, that you do have much more freedom with. The official name for it is the differentiator, and it appears in parentheses after the rest of your name. Here are some common uses for this bonus text:

    John Smith (MSN)
    John Smith (NEW YORK)
    To avoid confusion with other people with the same name.
    Jane Smith (DOE) Maiden name or other name you once went by.
    John Kennedy (JFK) Another name you are commonly known by.
    Alan Smithee (MOBILE) To let people know that you are rarely in the office.

    Originally, the differentiator also was submitted for approval, but the people who were responsible for approving them must have gotten tired of wading through thousands of boring requests for approval for this and other categories of personnel record changes that used to require approval. People are now simply trusted not to choose differentiators that are offensive or misleading.

    Some people have used this new freedom for humorous purposes. One prominent member of the application compatibility team has a non-English name that people often pronounce incorrectly. For the sake of discussion, let's say his name is Lav. At first, he signed his email

    –Lav, rhymes with Dave

    After a few months, based on a suggestion from a colleague (who might have been me), he changed it to

    –Lav, doesn't rhyme with "have"

    At this point, things got silly pretty quickly. A few months later, the signature changed to

    –Lav, rhymes with orange

    The last step was changing the differentiator after his name in the address book. If you look him up, he is listed as "Lav Pivo (ORANGE)".

  • The Old New Thing

    The dangers of setting your double-click speed too short


    After I noted how the window manager uses the double-click time as a basis for determining how good your reflexes are, people got all excited about reducing the double-click speed to make Windows feel peppier. But be careful not to go overboard.

    Back in the Windows 95 days, we got a bug from a beta tester that went roughly like this:

    Title: Double-clicks stop working after using mouse control panel
    Reproducibility: Consistent, hardware-independent
    Severity: Major loss of functionality

    1. Open the mouse control panel.
    2. Go to the Double-click speed slider.
    3. Drag the slider all the way to the right (fastest).
    4. Click OK.

    Result: Mouse double-clicks no longer recognized.

    We had to explain to the beta tester that, no, everything is actually working as intended. But if you set the double-click slider to the fastest setting, you had better be good at double-clicking really fast. You have clearly set the double-click speed was faster than you are physically capable of double-clicking. Maybe you can ask your twelve-year-old nephew to do your double-clicking for you.

    That's why there is the test icon next to the slider. Before clicking OK, make sure you can still double-click the test icon. If you can't, then you picked a setting that's too fast for your reflexes and you should consider a slower setting.

    Pre-emptive Yuhong Bao comment: In Windows 95, the test icon was a jack-in-the-box.

    [Raymond is currently away; this message was pre-recorded.]

  • The Old New Thing

    Why does Task Manager let me kill critical system processes?


    Because you told it to.

    If you run Task Manager, highlight a critical system process like Winlogon, click End Task, and confirm, then gosh darn it, you just killed Winlogon, and the system will reboot. (Assuming, of course, that you have sufficient privileges to terminate Winlogon in the first place.)

    Task Manager in earlier versions of Windows would try to stop you from killing these critical system processes, but its algorithm for deciding which processes were critical wasn't very smart, and if you were sufficiently devious, you could fake it out and make your program seemingly unkillable.¹

    To avoid being faked out, Task Manager simply stopped trying. Because if you don't do anything, then you can't do it wrong.


    ¹Of course, it was no such thing. You could still kill the program; you just had to use a program other than Task Manager to do it. (For example, you might try taskkill.)

  • The Old New Thing

    Why does my Run dialog say that tasks will created with administrative privileges?


    "I don't know what happened, but now when I open the Run dialog on my Windows Vista machine by typing Windows+R, there is a shield under the edit box that says This task will be created with administrative privileges. What's going on?"

    One my colleagues used psychic powers to solve this problem: "I imagine that you manually killed Explorer, and then you used an elevated command prompt or an elevated Task Manager to launch a new one. An elevated Explorer shows this message. To fix it, exit your elevated Explorer, and exit your running elevated copy of Task Manager (if any). Then type Ctrl+Alt+Esc to launch a normal (non-elevated) Task Manager and use File, New Task to run a new un-elevated Explorer."

    My colleague's psychic powers were right on target.

    "Your psychic powers are better than my memory. I now recall that I did kill and restart Explorer when debugging my shell extension, and I did so from a command line, which—given the evidence—must have been an elevated command prompt."

Page 1 of 4 (33 items) 1234