December, 2005

  • The Old New Thing

    2005 end-of-year link blowout sale

    • 11 Comments

    A quick list of links amassed over the past year. Not quite worth a posting on their own, but together they might mean something.

    [While Raymond was on vacation, the autopilot stopped working due to a power outage. This entry has been backdated.]

  • The Old New Thing

    On the abuse of properties

    • 15 Comments

    One thing that I see occasionally is the abuse of property syntax. IDispatch and CLR objects (and C++ objects if you want to avail yourself of a Microsoft-specific extension) support "properties", which syntactically look like fields but internally are treated as a pair of methods ("get" and "put"). An important principle is that given an object o and a property p, the lines

    (void)o.p;
    o.p = o.p;
    

    should be effectively nops. (Mind you, they might be really inefficient nops.)

    My favorite (or perhaps most hated) example of violating this principle is an object I saw many years ago that had a "print" property, which if set to true, caused the object to send itself to the printer. If you did

    o.print = true;
    o.print = true;
    

    then two copies of the object were printed.

    Property syntax mimics field syntax for a reason: Properties should behave like fields.

    (Plenty more guidance on properties can be found in the .NET Framework Property Usage Guidelines.)

    [While Raymond was on vacation, the autopilot stopped working due to a power outage. This entry has been backdated.]

  • The Old New Thing

    There's more to calling a function than just getting the types to match

    • 15 Comments

    Here's a classic novice error. You want to call a function, say GetBinaryType.

    void sample()
    {
     if (GetBinaryType(TEXT("explorer.exe"), ????)) {
      ...
     }
    }
    

    What should you write for those question marks? Well, the prototype says that the second parameter is an LPDWORD, so let's pass it one.

    void sample()
    {
     if (GetBinaryType(TEXT("explorer.exe"), (LPDWORD)NULL)) {
      ...
     }
    }
    

    Hm, but that crashes. Well, maybe we can pass it an LPDWORD this way:

    void sample()
    {
     LPDWORD lpdw;
     if (GetBinaryType(TEXT("explorer.exe"), lpdw)) {
      ...
     }
    }
    

    Hm, that still crashes. Oh wait, it's because of the uninitialized variable.

    void sample()
    {
     LPDWORD lpdw = NULL;
     if (GetBinaryType(TEXT("explorer.exe"), lpdw)) {
      ...
     }
    }
    

    No, that still crashes. Hang on, I know where I can get an LPDWORD.

    void sample()
    {
     LPDWORD lpdw = new DWORD;
     if (GetBinaryType(TEXT("explorer.exe"), lpdw)) {
      ...
     }
    }
    

    This code finally works! Okay, on to the next problem...

    Of course, the seasoned programmer still shakes his head. Just because the function prototype says that the parameter is an LPDWORD doesn't mean you have to have a variable whose type is LPDWORD. You merely need an expression whose type is LPDWORD.

    void sample()
    {
     DWORD dw;
     if (GetBinaryType(TEXT("explorer.exe"), &dw)) {
      ...
     }
    }
    

    Why am I telling you this?

    No, I'm not trying to insult your intelligence. I'm trying to get you to think like a novice. Sometimes you'll be reading a chunk of code and find something bizarro, like the fragments above with the new DWORD. When you do (for example, when chasing the memory leak in that code sequence), don't tear your hair out trying to find some deep meaning for the seemingly roundabout way of accomplishing a simple task. If you can think like a novice, you will merely recognize it as a classic beginner mistake, fix it, and get on with your life.

    [While Raymond was on vacation, the autopilot stopped working due to a power outage. This entry has been backdated.]

  • The Old New Thing

    If one certification is good, more must be better

    • 13 Comments

    In the discussion of driver signing, commenter ATZ Man suggested:

    Further, Microsoft should allow orgs that are peers of WHQL [to] certify drivers and allow drivers to obtain certs from any such org or set of such orgs as they choose. Over time users would know which orgs were on the ball and which had agendas.

    Would they?

    Let's take a real-world case where there are multiple certifying authorities, to see whether what this commenter predicts actually has come to pass.

    The United States has several bicycle helmet standards which a manufacturer can choose to meet. At a minimum, it must meet the requirements of the Consumer Product Safety Commission; this is the standard required by law. Beyond that, however, it's at the discretion of the manufacturer.

    I don't know about you, but I don't know my ASTM from a hole in the ground. Who's going to sit down and research the differences between CPSC, ASTM, SEI, Snell B-1990S, Snell B-1995, and ANSI? Did you know that there are four different certifying organizations for bicycle helmets? Did you even care?

    When I buy a bicycle helmet, I read the tag that says "Meets XYZ standards" and say, "Okay, cool, this helmet meets some standard that some committee established. It must be a safe helmet." End of story. I'm not a bicycle helmet expert. I don't want to be a bicycle helmet expert. I want somebody else to be the bicycle helmet expert and just tell me whether this helmet is okay or not.

    "Over time, users would know which helmet certifications were on the ball and which had agendas." Do you believe this has actually happened?

    [While Raymond was on vacation, the autopilot stopped working due to a power outage. This entry has been backdated.]

  • The Old New Thing

    Why did the Windows 95 CD have extra fun stuff?

    • 13 Comments

    Why did the Windows 95 CD have extra fun stuff, like the Good Times and Buddy Holly music videos, the Rob Roy trailer, and the cartoons by Bill Plympton? Because it was fun! Why does one have to justify having fun?

    In addition to the multimedia fun, there was also video game fun, with the addition of Pinball and the mercifully-forgotten hovercraft game Hover! (Some of us thought it was so awful, we secretly called it Hoover!)

    [While Raymond was on vacation, the autopilot stopped working due to a power outage. This entry has been backdated.]

  • The Old New Thing

    On the "Days without a pony" web page

    • 22 Comments

    Reader Mark Eichin was curious about the "Days with a pony" web page. Here's what it would look (suitably redacted) if it were still operating:

    December 23, 2005: Still no pony

    From: Raymond Chen
    To: Xxxx Xxxxxx
    Subject: Laptop order
    Date: Mon, 27 Mar 2000 09:47:19 -0800

    I want a pony and a train set and an NEC Versa SX laptop (NECVS4E0E7A).

    Maybe you can help.

    Did I mention the pony?


    From: Order Management
    To: Raymond Chen
    Subject: Order Confirmation
    Date: Fri, 31 Mar 2000 14:28:19 -0800

    Your order has been confirmed. Please contact your Central Sales Representative if you have any questions.

    Customer PO#1174384
    Order#5549416
    Order Date3/31/2000
    Item # Mfg Part# Description Price
    A143831 VS4E0E7A-0300A0 NEC VERSASX PII400 #,###.##
    0373140 OP-570-69002 NEC BATT PK ###.##
    A021502 KTN-VSLX/128 KINGSTON 128MB OD V ###.##
    A025063 3CXM556 3COM MCD 56K CELLUL ###.##
    A025848 CE3B-100BTX XIRCOM CREDITCARD E ##.##
    A136063 OP-270-69002-1 NEC DVD PC ACCELERA ###.##
    Total #,###.##

    From: Raymond Chen
    To: Xxxx Xxxxxx
    Subject: FW: Order Confirmation
    Date: Fri, 31 Mar 2000 15:12:19 -0800

    What, no pony?

    The laptop itself is still operational, assuming you don't need to see anything. The LCD backlight died a few years ago, so you either have to type blind or work in a really bright room. For some reason, the video output also died, so the standard fallback of using it as a very small desktop machine (with external keyboard and monitor) doesn't work. As a result, the machine sits in a drawer unused.

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

  • The Old New Thing

    Why do up-down controls have the arrows backwards?

    • 29 Comments

    When you create an up-down control (some people call a "spinner" control) in its default configuration, the up-arrow decrements the value and the down-arrow increments it. Most people expect the up-arrow to increment and the down-arrow to decrement. Why is it backwards?

    The up-down control is a victim of Windows' reversed y-axis.

    Mathematically, the (0, 0) coordinate should be at the bottom left corner of the screen (and in fact that's where OS/2 puts it), with y increasing as you move up the screen. Windows, on the other hand, puts the (0, 0) coordinate at the upper left corner, with y increasing as you move down the screen.

    What does that have to do with anything?

    The up-down control can be positioned horizontally or vertically. Let's first look at the less problematic horizontal configuration. Windows and mathematics agree that the x coordinate increases to the right, and the right-arrow (the arrow with higher x-coordinate) causes the value to increase. (Let's leave right-to-left languages out of the picture for the purpose of this discussion.)

    Once you have the horizontal version of the control working, converting it to a vertical control is a simple matter of interchanging the x- and y-axes.

    That's why the up-arrow decreases the value. The up-arrow points towards smaller y-coordinates and consequently decrements the value.

    It's perfectly logical and simultaneously counter-intuitive. (It's slightly more intuitive if you imagine the value attached to the up-down control as controlling the y-coordinate of an imaginary object on the screen. In that case, clicking the up-arrow causes the y-coordinate to decrease and the object moves up the screen.)

    Fortunately, this wackiness doesn't last long, because the moment you change the range of the up-down control from the (not very useful) default of 0–100 to whatever you actually need, the arrows behave "normally" again.

    Perhaps intuitiveness should have won out over logic. But what's done is done, and, as noted above, the problem goes away soon enough.

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

  • The Old New Thing

    The office disco party

    • 34 Comments

    One of the long-standing traditions at Microsoft is to play a prank on someone's office while they're away on vacation. You can imagine what most of these pranks are like, filling someone's office with packing peanuts or other materials, or relocating their office to an unlikely part of the building (the bathroom, the cafeteria), or something more subtle like mirror-reversing all the furniture in the office. Redecorating an office is a common theme, such as turning their office into a French bistro or a golf course (with real grass).

    One particularly memorable office redecoration was from 1996 or so. One of the managers, let's call him "Bob", had a bit of a reputation for being "cool" in a nightclubby sort of way. While Bob was away on vacation, his team set to work. They emptied his office completely, painted the walls black, removed the ceiling tiles to give it that "industrial" look, and installed a disco dance floor, disco lights, and a stereo with turntable.

    It was Disco Bob's Party Palace.

    When Bob returned, there was quite a happenin' disco party waiting for him.

  • The Old New Thing

    "Pro forma" was so 1990's

    • 12 Comments

    "Non-GAAP" is the new "pro forma".

    Remember the exciting dot-com boom days? Everybody was reporting "pro forma" results. Pro forma in the 1990's turned into a euphemism for "We just made this stuff up". But after the dot-com bust and a series of accounting scandals, the phrase pro forma turned into a bad word on Wall Street. People swore off that pro forma nonsense and returned to the good old GAAP numbers.

    But we all knew that that wouldn't last for long.

    But people aren't being so cheeky as to use the phrase pro forma. No, the magic phrase is now "non-GAAP". Punch that into your favorite search engine and watch all the people reporting earnings that do not conform to generally accepted accounting practices.

    Let's see how long before this ruse finally collapses. And how much money people lose as a result.

  • The Old New Thing

    Why does Windows setup lay down a new boot sector?

    • 77 Comments

    Why does Windows setup lay down a new boot sector? Because the alternative is worse.

    You would expect that after installing an operating system, the operating system should boot. If your boot sector is damaged, say because this is a brand new hard drive with no boot sector, or because it was infected with a boot sector virus, you expect the operating system's setup program to replace the boot sector with a good one. If it didn't, you'd have an operating system that didn't boot.

    Not the greatest introduction to a new operating system.

    I know some people are going to suggest, "Why doesn't the setup program ask before overwriting the boot sector?" But think about it. It's Christmas Day, you're installing Windows XP on your computer, you go through the setup process, and it asks you a question you can't answer. "Gosh, the computer says that I have a custom boot sector. It says that this could be for legitimate reasons, or it could be due to a virus. How the heck am I supposed to know the difference?" That's assuming they even read the dialog. A much more realistic scenario is, "Eek! The computer is asking me a scary question! How do I cancel out of this? I hate computers. They're so hard to use."

    Yes, this means that if you are an ultradweeb with a custom boot sector, you will lose it when you install Windows. But Windows isn't picking on you. It even destroys itself. If you take a Windows XP machine and install Windows 2000 onto it, the Windows 2000 setup program will lay down a new boot sector that knows how to boot Windows 2000 but doesn't know about Windows XP. You'll have to restore the Windows XP boot files to restore that functionality.

    [Update 9am: Even if Windows Setup did give you the option of "don't overwrite the boot sector" you still wouldn't like it. Windows Setup would get to the point where it lays down a new boot sector, and it says, "Ooh, an unrecognized boot sector, and the user said they want to leave it alone. Okay, I won't touch it. Now, how do I tell the foreign boot sector where I installed this operating system?" Since the authors of Windows Setup are not clairvoyant, they don't know what kind of boot sector you're going to have, so they won't know how to tell that foreign boot sector, "Please add 'Windows' to the list of known operating systems, and here is how you start it." The result: You just installed an operating system and have no way to run it.]

    Things are a little better starting with Windows XP Service Pack 2 and Windows Server 2003 Service Pack 1, though. Those and future versions of Windows setup check the version of the NTLDR file and will leave a newer version of the boot loader intact rather than overwriting it with an older version. Let's just hope that you're not installing because you need a fresh boot sector...

Page 1 of 4 (33 items) 1234