Monthly Archives: September 2005

WiFi in a Seattle hotel booked out by geeks.

I am staying in a hotel that has been booked out by a bunch of geeks in downtown Seattle. The interesting thing about it is that with so many wireless users around the network is completely saturated, and I’m not just talking about the wireless – I think that the link to the backbone is flooded as well. Its taking me ages to download my e-mail and RSS feeds.

Its not the hotel’s fault though – they probably aren’t equipped to cope with this kind of load

Someone sent this to me in the mail today :)

A little girl goes to his father and asks “Daddy, how was I born?” The father answers: “Well, daughter, I guess one day you will need to find out  anyway!   Your Mom and I first got together in a chat room on Yahoo.  Then I set up a date via e-mail with your Mom and we met at a cyber cafe.. We sneaked into a secluded room, where your mother agreed to a download from my hard drive. As soon as I was ready to upload, we discovered that neither one of us had used a firewall, and since it was too late to hit the delete button, nine months later a blessed little Pop-Up appeared and said:

You’ve Got Female!

In Seattle cutting code at 11pm . . .

I just got into Seattle this afternoon, checked into the hotel and then headed out to the “CodeSlam”. CodeSlam is an event that the GotDotNet team organised to show some MVPs some of the new stuff that they are doing. I can’t tell you anything about it – but its cool!

Not only will GotDotNet suck less, it won’t suck at all!

C# 3.0: Object and collection initializers.

I recently posted up about implicitly typed local variables in C# 3.0, the next feature I want to look at is object and collection initializers, however, before I go any further I want to point out the reason why I am looking at all these low hanging features.

Basically the small features that get introduced into a language are actually enablers for the more complex ones – otherwise, why would you bother? implicityly typed local variables enable anonymous types in LINQ query syntax – object and collection initializers are the same.

Object initializers are a shortcut syntax for instansiating and configuring an object instance. Lets take the following piece of valid C# code today:

  1 Customer c = new Customer();
  2 c.FirstName = "Joe";
  3 c.LastName = "Bloggs";
  4 c.Address = new Address();
  5 c.Address.Line1 = "42 Wallaby Way";
  6 c.Address.City = "Sydney";
  7 c.Address.State = "NSW";
  8 c.Address.PostCode = "2000";

With object initializers you could express this code as:

  1 Customer c = new Customer()
  2 {
  3 	FirstName = "Joe",
  4 	LastName = "Bloggs",
  5 	Address = new Address()
  6 	{
  7 		Line1 = "42 Wallaby Way",
  8 		City = "Sydney",
  9 		State = "NSW",
 10 		PostCode = "2000"
 11 	}
 12 }

The interesting thing here is that this code actually takes more space – so is it clearer? Its probably too hard to tell from this example, lets look at collection initializers as well:

  1 Customer c = new Customer()
  2 {
  3 	FirstName = "Joe",
  4 	LastName = "Bloggs",
  5 	Addresses = {
  6 		new Address ()
  7 		{
  8 			Line1 = "42 Wallaby Way",
  9 			City = "Sydney",
 10 			State = "NSW",
 11 			PostCode = "2000"
 12 		},
 13 		new Address ()
 14 		{
 15 			Line1 = "10 Downing Street",
 16 			City = "London",
 17 			State = "England",
 18 			PostCode = "123-ABC"
 19 		}
 20 };

In the above example the definition (use your imagination) for the Customer class has an addresses property and we are using a collection initializer to add elements to it. Collection initializers allow us to declare the elements of a collection (array or list) in one logical statement. In the case of initialising an array inline (which we can already do), the syntax becomes more compact:

  1 string[] strings = { "One", "Two", "Three" };

If you apply the implicit typing of local variables then it can be shortened even further to:

  1 var strings = { "One", "Two", "Three" };

Lists aren’t really any different except you need to be explicit about the type of list you are instansiating (note it doesn’t need to be generic, it could be ArrayList):

  1 List<string> strings = new List<string> { "One", "Two", "Three" };

But even this could be shorter:

  1 var strings = new List<string> { "One", "Two", "Three" };

Finally, something that I thought was interesting is that the following is invalid:

  1 public class Foo
  2 {
  3 	public Foo Self;
  4 }
  5 
  6 public class Program
  7 {
  8 	public static void Main()
  9 	{
 10 		Foo f = new Foo() { Self = f };
 11 	}
 12 }

The C# compiler will barf because “f” is unassigned. But I feel that by the time the object initializer is executed it is. Its just one of those corner cases where it could go either way, so in C# they have locked it off with a compiler error. Next up we will look at anonymous types.

Worked from the park today.

I had to knuckle down and write a document today that required a fair bit of thought so I headed into the city instead of working from home (its too easy to find distractions at home sometimes). After spending a few hours in Starbucks (green tea before you ask) I decided that I needed a change of scenery so I headed outside.

My original plan was to set at some public tables and chairs in Civic but they were all being used so I went down to the park and found a picnic table to sit at. Here is a satellite image that I spent most of the day in.

I’m really starting to get into this whole mobile computing lifesytle. All I need now is another battery or two so that I can run the whole day of battery power and I need not visit a coffee shop at all . . .