Servergeek
Mickey Williams' weblog


Powered by Blogger Pro™

Friday, November 21, 2003

Estimating the Airspeed Velocity of an Unladen Swallow


Via Chris Anderson, who points to JFo, style.org > Estimating the Airspeed Velocity of an Unladen Swallow

Thursday, November 20, 2003

Longhorn:Pissed off at Windows Activation


In the Junie B. Jones stylee...

So I installed two instances of LH on my laptop. About 16 days ago or so (apparently). And didn't bother to set up networking on either instance. And then started working 50+ hrs a week at my consulting gig where they unreasonably expect me to develop web services using something other than Longhorn. And also racing way too fast down very steep hills on my racing deck wearing shorts, but that's another story about the end-of-the-year race at WLAC and anyway I was really busy. Until I finally got a lunch break today. And team-mate Roman Kiss asked me a Longhorn question (which hardly ever happens because he is an uber geek). And I wanted to answer the question. And the most excellent Windows Activation service, which is apparently the only part of Longhorn that is working at full efficiency won't let me log on until I activate it. Except I don't have a network connection. And the helpful toll-free 888 number for activation uses voice recognition instead of Indians like everybody else, and doesn't understand Louisiana-mixed-with-Southern-California geek accents. And anyway even after talking very Nebraska-like, it won't give me the option of activating LongHorn anyway. So my expectations are not currently in line with my experience. So I'm getting much better at installing LongHorn. And if you've just installed LongHorn, don't wait until the last minute to set up the VPC network.

Whidbey: Iterators in C#


I'm starting to build some sample code for course material, general presentations, and the new book. From time to time, I'll post some material - mainly so I can find it later ;)

Iterators are specialized methods that you write in place of the standard verbose enumerator pattern. During compilation, the C# compiler translates your iterator's code into an implementation of IEnumerable or IEnumerator. Iterators are generally CLS compliant, as languages such as Visual Basic see your iterator just as if you had implemented the enumerator pattern.

The introduction of iterators enable me to reduce the amount of complex code that I need to write. Although I'm pretty well familiar with writing enumerators nowadays, I'm happy to leave them behind in general cases where an iterator will suffice. Here's an example of a class (Racers) that exposes three enumerators, each of which are called in different ways:

using System;
using System.Collections;
using System.Collections.Generic;

namespace IteratorDemo
{
	class IteratorApp
	{
		static void Main(string[] args)
		{
			Racers racers = new Racers();
			// Calls GetEnumerator
			foreach (string r in racers) 
				Console.WriteLine(r);
			// Calls Grid
			foreach (string r in racers.Grid)
				Console.WriteLine(r);
			// Calls BottomUp
			foreach (string r in racers.BottomUp())
				Console.WriteLine(r);
			Console.ReadLine();
		}
	}

	class Racers: IEnumerable<string>
	{
		string [] _grid = {"Mickey", "Ali", "Kenzie"};
		public IEnumerator<string> GetEnumerator()
		{
			foreach (string racer in _grid)
				yield racer;
		}
		public IEnumerable<string> Grid
		{
			get
			{
				foreach (string racer in _grid)
					yield racer;
			}
		}
		public IEnumerable<string> BottomUp()
		{
			for (int i = _grid.Length - 1; i >= 0;  --i)
				yield _grid[i];
		}
	}
}

Home