November 2006 - Posts

What is infinity? It's commonly represented as the lemniscate (∞), that funny sideways 8 that conjures to mind a Mobius strip. If you wanted to get hard core about it you could start talking about Cantor sets, aleph zero, aleph one and suchlike. You also get all sorts of cool paradoxes with inifinities, such as Hilberts Grand Hotel. Anyway, to get back on track, that funky little symbol allows us to imagine a major misconception, that infinity is a thing, it's not, it's a process, an algorithm if you like. For example, the infinity of natural numbers can be represented as such:

int i = 1;

while (true)

{

   yield return i++;

}

Of course we all know that would lead quickly to an overflow exception. Nonetheless the algorithm expresses an infinity. No matter what happens, another trip round the loop conjures up a bigger number, and it will never, ever end. What is especially interesting about putting it in an iterator means that we only get the next item when we need it. Thus it is possible to create "inifinite" algorithms for many classes of number where we do not have to know the whole sequence up front but can generate it on the go as it were. Primes and Fibonacci numbers are just two examples. Imagine we create an iterator that in theory would enumerate all primes it is possible to express in a 64-bit number. That's a lot of primes, however we may not need all of them. For example if we were attempting to crack a message encypted with a private key which is the product of two primes, we could set two copies of our iterator going, each generating primes as it goes, and stop when we find the match. Whilst our iterator in theory never ends, in practise it does end when we find what we're looking for. Obviously we could be even cleverer and feed a single prime generating iterator as an input into a Cartesian Product iterator.

Here's a slightly different use of an "infinite" iterator: as a task scheduler. Imagine that we have a set of recurring tasks, so we have a thread that will service those tasks. How it operates is it does a foreach on an iterator and executes the task (which could be a class, delegate etc) as it receives them. Here's some pseudo code for the iterator:

while (true)

{

   if (exit)

   {

      yield break;

   }

   yield return CurrentTask();

   Sleep();

}

 

Interesting isn't it? The calling thread does not need to care about times or sleeping or anything like that, it just happily enumerates the iterator until it the iterator ends. The iterator sleeps when it needs to sleep, ends when it needs to end, and delivers tasks when they need to be executed.

 

There's other occasions where you might be enumerating items with no real end. One would be a kind of discovery engine. Imagine that you send out a UDP broadcast on a given port, and then listen for incoming responses, as well as other machines broadcasting. You never really end since a new machine could come online at any time. No problem, hook up all your listening code inside an iterator, and then foreach your way through machines either until you've got enough, have to shut down or whatever.

 

By hiding such complex threaded code inside what appears at first glance to be a simple collection type class you save the developers using your class an awful lot of trouble. So they're not just for collection classes, well I suppose you could argue that they still are, but now the collection potential size can be "grown" to represent inifinite collections.

 

Try doing that with an array!

Here's a thing, I hate hate hate hate spam SMS. If I receive spam SMS I track down not only the sending company but also the company that supplied the data and ensure they both put me on a no-spam list. Accordingly I get very few spam SMS's, but I do get some that slip through the net. What's really been annoying me lately is the number of restaurants that assume I want to keep current with every tiny little special they may have. At no point did I ever suggest I'd like this information, but they require your cellphone number for making a booking, so they use the booking register as a means of mining for addresses to spam. They even swap this information between branches.

From Buys Inc:

If a consumer receives a commercial spam message, whether by email or SMS, he or she has the following rights:

  1. The right to be removed from the spammer’s database
  2. The right to know how the spammer got hold of the consumer’s email address or cell phone number
Spammers who fail to unsubscribe consumers who request it, or who refuse to provide consumers with the source of their personal information, may face criminal prosecution, fines and even prison sentences.
The Protection of Personal Information Act due in 2008 will make this "cross-pollination" of information illegal. If a restaurant got your cellphone number for a booking, that's all they could use it for. Oh, by the way, the offending restaurant was Jimmy's Killer Prawns. Make sure you're careful with the information you give them or you too could be facing spam SMS's.

Just a couple of follow-ups to some earlier posts.

No Vista for me

Yep, VS2002 and VS2003 are still not supported on Vista. Microsoft is saying absolutely nothing about the issue in the hopes it'll go away. Well, it will. I was chatting to some friends the other day and here are some details on companies that will not be migrating to Vista largely due to lack of .NET 1.1 support: 2 medical aids, an investment bank, one gigantic trading house, a large manufacturing concern and a large retailer. They, like me, see no reason why we should be forced to upgrade code that's working fine simply because Microsoft couldn't be bothered to support their own products. At least two of these companies are rethinking their Enterprise Software Assurance due to this issue.

I simply cannot stand how stupid and idiotic Microsoft are being about this issue. They're hurting their image amoungst developers and IT managers in horrific ways. Of the friends I polled, all in senior technical positions, 100% said they were upset with Microsoft about this. Not neccesarily for the actual lack of support for VS2003, but for the way Microsoft has handled this issue. I mean, refusing to even let the community know what issues we might expect! How childish can a company get? Others were upset about what this imples for backwards compatibility with other Microsoft products.

Kent Hovind coming to SA?

Yep, he's been convicted on all 58 charges, and will be sentenced on January 9th. He is currently in jail as he is considered a flight risk. I guess that means he won't be coming to South Africa. I wonder what other criminals we can scrape up to represent South African creationists? Much amusement from me, I guess less so from my creationist bunnies ;-D

 SADeveloper Article Rankings

Go to SADeveloper, and look at each of the Most Recent Articles. Note that the only comment/ranking is given by me to RudolfH's MSBuild article. Also note the dates on those articles. I certainly have no desire to contibute to a completely uninterested community, I guess I'm not the only one. One of my colleagues recently swore off SADeveloper, disgusted with the lack of decent content. I admit I haven't bothered going to it in over a month and a half, and from the looks of things I've missed nothing. Anyone got any ideas on how to spruce up the site? I'd like to see more about South African Development than development in general, you know, information on interesting projects, who's doing what for who kind of thing. Also, a couple of project areas (ala GotDotNet) might be nice.