February, 2009

  • The Old New Thing

    What are your high school language students complaining about today?

    • 29 Comments

    One of my friends is a high school language teacher, and I used to ask her, "So, what are your students complaining about today?" That was back when her school used the traditional "First we learn the personal pronouns, then we learn the present tense of regular verbs, then we learn nouns in nominative case..." grammar-based language acquisition system. That system works reasonably well for me (although I prefer to learn the major points all at once rather than in pieces), but it requires an appreciation for rules (and their exceptions) that most high school language students don't really have.

    That's why I like to ask her what her students are complaining about. One day it'll be "Why do I have to learn noun genders?", another day, it'll be "Why do we have to change the form of the verb depending on who the subject is?", and another day it'll be "Why are there two different past tenses?" These students usually fail to realize that their own native language suffers from the same (if not more) "Why?" questions. Why does English have both a simple present tense and a present tense with progressive aspect? (And why are there so many exceptions? For example, why can't you say "He is owing me five dollars"?)

    Anyway, one day, when I asked her, "What are your students complaining about today?" I was expecting another point of grammar. What I wasn't expecting was, "They want to know why they need to learn synonyms."

    I guess they figured that once they learned the word big, there would be no need to know words like large, huge, grand, massive, or vast.

    I no longer ask this question, because my friend now teaches based on the principle of comprehensible input, wherein students are exposed to the language by means more closely mimicking the natural way language is acquired: employing stories and conversations, and using contextual or visual cues to infer the meanings of unknown words and tenses instead of learning them from a vocabulary list and a rule sheet. And it's working fantastically. Now I don't have to ask her about how the students are doing: She happily volunteers it! A few years ago, she was excited about students in their sixth week of class reading a story that would have stymied second-year students under the old system. Another story that stands out for me was students who knew where to put accent marks in relatively unfamiliar words even though they were never formally taught the rules on accent marks; they just used their gut feeling.

    Most recently, it was "I formally introduced the past tense and asked one student to give me a sentence in the past tense. He said that when he was younger, he once took his dad's car for a joy ride. Well, that quickly led to a game of one-upsmanship with students fighting to tell their own stories of juvenile delinquency. And they all used the past tense." Sure, they didn't get the irregular verbs quite right, but hey, they didn't get the irregular verbs right when they were learning English for the first time, either.

    Happy birthday, Rebecca!

  • The Old New Thing

    How does Raymond decide what to post on any particular day?

    • 35 Comments

    Occasionally somebody asks about the timing of an entry I've written and wants to know how far ahead with this blog thing I really am.

    To give you an idea of how far in advance I write my blog entries, I wrote this particular entry on February 13, 2008. Generally, the articles are published in the order I wrote them; this particular entry ended up on February 27, 2009 because that was the next available open day. If the big news topic of February 27th, 2009 happens to be related to this entry, it's just a coincidence.

    Now, with a buffer of over a year, I do have quite a bit of leeway in choosing when any particular article is published. Although articles in general just get slotted in for the next open day, I will occasionally arrange for one to come out on a thematically-related day. Sometimes the connection is blatant, like writing about time and time zones on the Fridays before Daylight Saving Time transitions, or writing about Hallowe'en on, well, Hallowe'en. More often the connection is low-key, like telling a story about the economics of parking tickets on a day when parking is free in Seattle or warning about fake guacamole on the Friday before the Super Bowl. And sometimes the connection is impossibly obscure, like taking a story that I know a friend will like and slotting it in on their birthday, anniversary, or some other day meaningful to them.

    (To answer Paul's specific question: I found the article on guacamole and said, "That would be a great article to use for the Super Bowl." Since I already had a Super Bowl article picked out for 2007, the guacamole article was slotted in for 2008.)

    There are other patterns you may have picked up on:

    • Mondays are usually spent "answering viewer mail" (i.e., taking topics from the Suggestion Box).
    • Less technical articles appear towards the beginning of the week; more technical articles appear later in the week. Tuesday in particular tends to get the funny stories.
    • There is usually one e-mail related posting per month.
    • There is usually one Microspeak posting per month.
    • Sometimes an entire week is devoted to a theme, such as the annual CLR Week.
    • An unusually short or unusually long technical post is usually balanced by an amusing non-technical post. (I have a stash of about a hundred of these "light diversions".)
    • I tend to avoid technical topics on major holidays.

    But generally, it's just a FIFO queue.

    Oh, and right now, the queue is full up through the beginning of June 2010.

  • The Old New Thing

    Pressing a registered hotkey gives you the foreground activation love

    • 24 Comments

    One category of application that people complained about is the application launcher which keys off a hotkey and doesn't get the foreground love.

    Well, except that windows with registered hotkeys do get the foreground love.

    After you call the RegisterHotKey function to register a hotkey, the window manager will send you a WM_HOTKEY message when the user presses that hotkey, and along with it, you will get the foreground love. If you call SetForegroundWindow from inside your hotkey handler, the foreground window will change according to your instructions.

    A special administrator-only list of programs which are exempt from SetForegroundWindow rules would just be adding another round to the game of walls and ladders. All that'll happen is that programs, when they install, will place themselves in the Exempt from the normal rules list, and you're back where you started.

    "Oh no, I'll super-protect that registry key so that the only way to add an entry to it requires a human being to respond to a dialog box confirming that the entry is being added."

    Well, for one thing, that doesn't actually stop installers with administrator privilege, since they can just remove the super-protection and update the key anyway. (Administrator privilege is like that.) And even if you somehow manage to super-protect the setting (how? beats me), the next stage is application vendors (or system administrators attempting to deploy the application across their company) asking for a programmatic way to add their program to your super-protected list of exemptions. And then you're back to where you were.

  • The Old New Thing

    Star Trek meets The A-Team

    • 8 Comments

    Rumors swirl that there's a movie version of The A-Team in the works. If they haven't decided on the casting yet, here's an option they may have overlooked: The cast of Star Trek.

    (I like how in the clips used in the fake trailer, they use one of an episode where Kirk is old. And in Hollywood, making a character older means graying their hair. They never gain weight when they age, unlike the actors themselves.)

  • The Old New Thing

    Smart quotes: The hidden scourge of text meant for computer consumption

    • 43 Comments

    Smart quotes—you know, those fancy quotation marks that curl “like this” ‘and this’ instead of standing up straight "like this" 'and this'—are great for text meant for humans to read. Like serifs and other typographic details, they act as subtle cues that aid in reading.

    But don't let a compiler or interpreter see them.

    In most programming languages, quotation marks have very specific meanings. They might be used to enclose the text of a string, they might be used to introduce a comment, they might even be a scope resolution operator. But in all cases, the language specification indicates that the role is played by the quotation mark U+0022 or apostrophe U+0027. From the language's point of view, the visually similar characters U+2018, U+2019, and U+02BC (among others) are completely unrelated.

    I see this often on Web sites, where somebody decided to "edit" the content to make it "look better" by curlifying the quotation marks, turning what used to be working code into a big pile of syntax errors.

    I even see it in email. Somebody encounters a crash in a component under development and connects a debugger and sends mail to the component team describing the problem and including the information on how to connect to the debugger like this:

    WinDbg –remote npipe:server=abc,pipe=def

    Or maybe like this:

    Remote.exe “abc” “def”

    And you, as a member of the team responsible for that component copy the text out of the email (to ensure there are no transcription errors) and paste it into a command line.

    C:\> Remote.exe "abc" "def"
    

    and you get the error

    Unable to connect to server ôabcö
    

    What happened? You got screwed over by smart quotes. The person who sent the email had smart quotes turned on in their email editor, and it turned "abc" into “abc”. You then got lulled into a false sense of security by the best fit behavior of WideCharToMultiByte, which says I can't represent “ and ” in the console code page, but I can map them to " which is a close visual approximation, so I'll use that instead. As a result, the value you see on the command line shows straight quotes, but that's just a façade behind which the ugly smart quotes are lurking.

    I've even seen people hoist by their own smartly-quoted petard.

    I can't seem to access a file called aaa bbb.txt. The command

    type “aaa bbb.txt”

    results in the strange error message

    The system cannot find the file specified.
    Error occurred while processing: "a.
    The system cannot find the file specified.
    Error occurred while processing: x.txt".

    Why can't I access this file?

    Somehow they managed to type smart quotes into their own command line.

    So watch out for those smart quotes. When you're sending email containing code or command lines, make sure your editor didn't "make it pretty" and in the process destroy it.

    Exercise: What is wrong with the WinDbg command line above?

    Bonus chatter: PowerShell is a notable exception to this principle, for it treats all flavors of smart quotes and smart dashes as if they were dumb quotes and dumb dashes. From what I can tell, you have this guy to thank (or blame).

  • The Old New Thing

    Rob Cockerham investigates those companies that pay cash for gold

    • 9 Comments

    Rob Cockerham seems to have a lot of spare time, which is great for the rest of us, because he investigates all those things we simply don't have the time for, and then posts the results on his Web site ("The sixth-best website in the world").

    Today's highlight is a pair of investigations he performed some time ago which seem to show two sides of one industry.

    That Web site is a sinkhole of time-wastage. If you're not careful, you'll find yourself clicking around from story to story, like the How much is inside? adventures, in which he investigates things like how many threads per inch are there in 360-thread count pillowcases? Or his gallery of costumes (for Hallowe'en or other events), including my favorite: Paparazzi.

  • The Old New Thing

    Email tip: Just because you get answers when you misuse a mailing list doesn't doesn't mean you should continue to misuse it

    • 11 Comments

    A few years ago, there was a question on a mailing list for topic X, but the question was about unrelated topic Y. The question was nevertheless answered by the people on the topic X mailing list out of the kindness of their hearts (above and beyond the heart-sourced kindness that powers most mailing lists in the first place). I pointed out that the question really had nothing to do with topic X, and consequently the Y-Users list was a better place for the question.

    The person responded,

    Yes, I know, but X-Users always provides a quick reply and a quick solution.

    In other words, the person was sending questions to the X-Users mailing list knowing full well that the question was not appropriate for the mailing list, but just relying on the fact that the members of the X-Users list are kind-hearted people who will help out even if the topic lies outside their area.

    I pointed out, "You can call 9-1-1 to get driving directions quickly, but it's probably not the right things to do."

  • The Old New Thing

    Why is there no supported way to get the command line of another process?

    • 28 Comments

    Commenter Francisco Moraes wonders whether there is a supported way of getting the command line of another process. Although there are certainly unsupported ways of doing it or ways that work with the assistance of a debugger, there's nothing that is supported for programmatic access to another process's command line, at least nothing provided by the kernel. (The WMI folks have come up with Win32_Process.CommandLine. I have no idea how they get that. You'll have to ask them yourself.)

    That there isn't is a consequence of the principle of not keeping track of information which you don't need. The kernel has no need to obtain the command line of another process. It takes the command line passed to the CreateProcess function and copies it into the address space of the process being launched, in a location where the GetCommandLine function can retrieve it. Once the process can access its own command line, the kernel's responsibilities are done.

    Since the command line is copied into the process's address space, the process might even write to the memory that holds the command line and modify it. If that happens, then the original command line is lost forever; the only known copy got overwritten.

  • The Old New Thing

    Announcements on the ferry, and hills that grew while I was away

    • 8 Comments

    This weekend is the annual Chilly Hilly bike ride, an early wake-up call to bicyclists in the Seattle area to get their act together and hit the road.

    Last year, I joined my 2999 closest friends up and down the hills of Bainbridge Island. Unfortunately, the hills had grown taller in the two years since my last ride.

    There was an announcement on the ferry. It went something like this: "Your attention please. There is a bicycle on the car deck that has fallen over onto its side. Repeat: A bicycle has fallen onto its side."

    It took a few seconds for the joke to sink in with all the people on the ferry, but after a short while, the passenger deck was chuckling.

  • The Old New Thing

    Foreground activation permission is like love: You can't steal it, it has to be given to you

    • 48 Comments

    This is the blog entry that acted as the inspiration for the last topic in my 200 PDC talk.

    When somebody launches a second copy of your single-instance program, you usually want the second copy to send its command line to the first instance (and deal with the current directory somehow), and then you want the first instance to come to the foreground. But a common problem people run into is that when the first instance calls SetForegroundWindow, it fails.

    The problem with this design is that as far as the window manager is concerned, what happened is that the first instance received a message and then decided to steal foreground. That message wasn't an input message, so the window manager sees no reason for the first instance to have any right to take the foreground. There is no evidence that the first instance is coming to the foreground in response to some user action.

    There are a variety of ways of addressing this problem. The easiest way is simply to have the second instance make the call to SetForegroundWindow. The second program has permission to take the foreground because you just launched it. And if a program can take the foreground, it can also give it away, in this case, by setting the first program as the foreground window.

    Another way to do this is to have the second program call the AllowSetForegroundWindow function with the process ID of the first program before it sends the magic message. The AllowSetForegroundWindow function lets a program say to the window manager, "It's okay; he's with me." And then when the first program finally gets around to calling SetForegroundWindow, the window manager says, "Oh, this guy's okay. That other program vouched for him."

    If you are transferring foreground activation to a COM server, you can use the corresponding COM function CoAllowSetForegroundWindow.

    In all cases, note that you can't give away something that's not yours. If you don't have permission to take foreground, then calling AllowSetForegroundWindow (or one of its moral equivalents) will have no effect: You just told the window manager, "It's okay; he's with me," and the window manager replied, "Who the hell are you?"

    Pre-emptive snarky comment: "There are some really sneaky people who found a way to circumvent the rules and steal foreground activation." Well yeah, and there are some really sneaky people who find ways to steal love, so there you have it. If everything is right with the world, both groups of people will eventually be found out and made to suffer for their malfeasance.

    Update (02/21): Deleted all comments that showed ways of circumventing the rules. Duh, people.

Page 1 of 4 (32 items) 1234