The Old New Thing
Practical development throughout the evolution of Windows.
Latest posts
What happened to the Search option on the right hand side of the Start menu?
You may have noticed that in Windows Vista Service Pack 1, the Search option on the right hand side of the Start menu has been removed. What happened to it? It's redundant with the Search Box, that thing that has the keyboard focus when you initially open the Start menu. (But if you really want to open Explorer in Search mode, you can still type Windows+F or press F3 when focus is on the Start menu.) And if you want to plug into the search protocol that the Start menu uses, this MSDN page provides a sample registration and describes what sorts of queries you will be handed by the shell.
The Seattle Danskin Women’s Triathlon 2008
This Sunday will be the Nth annual Seattle Danskin Women's Triathlon (for some value of N greater than 1), the largest women-only triathlon. I learned about this event last year when I saw that the express lanes on the I-90 bridge were crowded with bicyclists, and I went online to try to figure out what was going on. As I clicked around, I found the Volunteer Site and was particularly impressed with the Swim Angels. (More details.) These are strong women swimmers whose job it is to accompany the weaker swimmers and provide moral support. I was chatting with a friend of mine, who noted that one of the firs...
The implementation of iterators in C# and its consequences (part 4)
You can breathe a sigh of relief. Our long national nightmare is over: this is the end of CLR Week 2008. We wind down with a look back at iterators. Michael Entin points out that you can use C# iterators to make asynchronous code easier to write. You can use C# iterators for more than simply iterating. The automatic conversion of straight line code into a state machine is handy when you want an easy way to write, well, a state machine. It's one of those things that's blindingly obvious once you look at it the right way. The transformation that the statement induces on your function turns it...
The gradual erosion of the car trip experience
How will kids today learn to get along with their siblings? I just learned that another of the basic childhood conflict resolution scenarios has disappeared, thanks to the dual-screen DVD player and entertainment system for your car, so each kid can remain content without the burden of having to interact with their annoying brother or sister. The traditional car ride games will slowly fade away, replaced with questions like, "Grandma, where's the Nintendo?" Why stop there? Why not just equip the car with tranquilizing gas in the back seat? The kids go in, you knock them unconscious, and you wake them up when y...
The implementation of iterators in C# and its consequences (part 3)
I mentioned that there was an exception to the general statement that the conversion of an iterator into traditional C# code is something you could have done yourself. That's true, and it was also a pun, because the exception is exception handling. If you have a try ... finally block in your iterator, the language executes the finally block under the following conditions: After the last statement of the try block is executed. (No surprise here.) When an exception propagates out of the try block. (No surprise here either.) When execution leaves the try block via yield break. When the iterator is ...
The implementation of iterators in C# and its consequences (part 2)
Now that you have the basic idea behind iterators under your belt, you can already answer some questions on iterator usage. Here's a scenario based on actual events: I have an iterator that is rather long and complicated, so I'd like to refactor it. For illustrative purposes, let's say that the enumerator counts from 1 to 100 twice. (In real life, of course, the iterator will not be this simple.) IEnumerable<int> CountTo100Twice() { int i; for (i = 1; i <= 100; i++) { yield return i; } for (i = 1; i <= 100; i++) { yield return i; } } As we learned in Programming 101, we can pull...
The unwritten rule of riding a Seattle Metro bus
The Metro King County transit site has all the facts about how to ride the bus, but there's another rule that is applied by convention rather than by any formal codification: For some reason, and I see this only in Seattle, it is customary to say Thank you to the bus driver as you get off the bus. Tip for new riders: If you aren't familiar with the area, you can ask the bus driver to announce the stop you intend to get off at. Bonus tip for bicyclists: There is an experimental program running this summer to allow bicyclists to ride out-of-service buses across the 520 bridge for free. You have to get o...
The implementation of iterators in C# and its consequences (part 1)
Like anonymous methods, iterators in C# are very complex syntactic sugar. You could do it all yourself (after all, you did have to do it all yourself in earlier versions of C#), but the compiler transformation makes for much greater convenience. The idea behind iterators is that they take a function with yield return statements (and possible some yield break statements) and convert it into a state machine. When you yield return, the state of the function is recorded, and execution resumes from that state the next time the iterator is called upon to produce another object. Here's the basic idea: All the loc...
Psychic debugging: Why can’t StreamReader read apostrophes from a text file?
As is customary, the first day of CLR Week is a warm-up. Actually, today's question is a BCL question, not a CLR question, but only the nitpickers will bother to notice. Can somebody explain why StreamReader can’t read apostrophes? I have a text file, and I read from it the way you would expect: StreamReader sr = new StreamReader("myfile.txt"); Console.WriteLine(sr.ReadToEnd()); sr.Close(); I expect this to print the contents of the file to the console, and it does—almost. Everything looks great except that all the apostrophes are gone! You don't have to have very strong psychic powers to f...