Andy's observations as he continues to attempt to know all that is .NET...

Tuesday, October 28, 2008

PDC 2008, Day one

This is my first PDC, so not sure what to expect in terms of quality of speakers and content.  Key note on cloud services the new windows platform Windows Azure was a little disappointing based on the fact that it was a developer audience.  In essence Microsoft are providing a platform for other companies to take advantage of large distributed data centres.  Microsoft has some experience in this space in providing Windows Update, MSDN content , Hotmail , Live services, these services will be ported to the new platform to allow them to self validate the platform, and offer others the ability to out source the data centre services.    There will be a short period of time were these services will be free, but in 2009 MS will start to charge for the cloud services based on usage and SLA.  Google's cloud based computing has been a serious threat to MS traditional inside the enterprise model, companies have started looking to outsource basic IT, Daily Telegraph recently announced the use of Google for email and office based apps..Its still yet to be seen if large corporations with lots of IPR will ever rely on a third party to hold and manage their data, and this fact plays nicely into Microsoft's offering as they have concentrated on allowing enterprises to utilise the cloud with existing applications inside the enterprise, thus enabling perhaps companies to shift over time, and deciding what is ok to put into the cloud.  This is a key advantage they have over the google offering...Other key advantages is that as an MS developer I continue to use the same tools and languages to target the cloud as I do inside the enterprise, and thats huge.


Whilst all that fluffy cloud stuff was interesting, for me the best talk was on C# 4.0 by Anders.  Anders is not only a seriously smart guy but a great presenter too.  The high lights where

Dynamic language feature support

Co-variance on generic interfaces

Default/Optional parameters

The dynamic language support was very cool..  Microsoft has been working on a DLR ( Dynamic Language Runtime ) for some time to make it easier to write dynamic languages, IronPython and IronRuby utilise common functionality to deliver dynamic language behaviour.  C# will now utilise some of that same functionality, by introducing the dynamic keyword.  So I can write


dynamic foo = 10

foo = "hello"

foo = 5.6


When you call a method on foo it is late bound, this late binding is done by the fact that foo is of type DynamicObject which has various methods on it like GetMember , InvokeMethod which take a string to represent a Member/Method name.  The main aim of this is to allow better interop between staticly typed languages and dynamic ones.  Thus calling java script from silverlight is now something like this

<h1 id="title">Hello</h1>


dynamic element = HtmlPage.Document.title;

element.innerText = "Good Bye";


Also COM interop via this mechanism means no PIA's.  and a programming model that looks very easy to consume.  It also has massive ramifications for Active Record pattern utilised by Ruby on Rails, and for processing XML documents using a dot notation that matches the names of elements.  The creation of REST proxies would also seem extremely straight forward.


Support for co-variance List<string> can now be turned into an IEnumerable<object>.  Something that has been very frustrating in the past. 

Finally we can write C# methods

public int Add( int lhs = 1, int rhs = 1 )


We can therfore call Add(), Add(1) and Add(1,1) to produce the same result or


Add( rhs: 1 , lhs : 1 )


Day 2 is now hopefully plenty of goodness coming

Wednesday, October 01, 2008

WARNING...Look after your speakers badge

I noticed today that there is a site called and so I clicked on it...and yo and behold its a series of strange locations featuring my Speakers card from Software Architecture week.  A quick whois lookup revealed the culprit a fellow Developmentor instructor....

Think I'll be looking after my speaker badge in future...

Random Sampling extension method

Had reason recently to select a random sample of data from a stream of elements.  The amount of samples I needed to take was finite but what was unknown was the number of elements in the input stream.  I managed to find various implementations of an IEnumerable extension method on the net, but all the ones I found would cache the entire stream before selecting the sample.  This clearly isn't scalable as the input stream increases in size.

After a look around I found this blog article that describes how to implement Reservoir sampling without the need to keep all the items.  This then allowed me to write a Random Sample extension method to IEnumerable<T> to do what I needed.

public static IEnumerable<T> RandomSample<T>(this IEnumerable<T> rows, int nSamples)
          Random rnd = new Random();

          T[] sample = new T[nSamples];

          int nSamplesTaken = 0;

          foreach (T item in rows)
              if (nSamplesTaken < sample.Length)
                  sample[nSamplesTaken] = item;
                  // As the amount of samples increases the probability
                  // of including a value gets less..due to the fact
                  // that it has a greater chance of surviving if it gets
                  // placed into the sample over earlier selections

                  if (rnd.Next(nSamplesTaken) < nSamples)
                      sample[rnd.Next(nSamples)] = item;


          if (nSamplesTaken >= nSamples)
              return sample;
              return sample.Take(nSamplesTaken);

About Me

My photo
Im a freelance consultant for .NET based technology. My last real job, was at Cisco System were I was a lead architect for Cisco's identity solutions. I arrived at Cisco via aquisition and prior to that worked in small startups. The startup culture is what appeals to me, and thats why I finally left Cisco after seven years.....I now filll my time through a combination of consultancy and teaching for Developmentor...and working on insane startups that nobody with an ounce of sense would look twice at...