January 2004 - Posts

Assembly References

I've added the ability to add assembly references when compiling with Code Blog.  Something that threw me is the strong name key used to sign the 'System' and 'System.Web' assemblies are different!  To make life easy for you I'm now using LoadWithPartialName.  To reference the correct version of 'System.Web' you can just do "System.Web, Version=1.0.5000.0".

I've updated the challenge (another easy one).  If you fancy a go, subscribe to the feed and post a submission.  I'm looking for more ideas for challenges.  If you have any ideas, please send them (along with NUnit tests and a stub implementation) here.

Posted by Jamie Cansdale | 2 comment(s)
Filed under:

((ArrayList)list).Sort();

Within minutes of posting a link to Code Blog, someone submitted the following solution...

    public IList Sort(IList list)
    {
        ((ArrayList)list).Sort();
        return list;
    }

This is certainly the simplest possible solution to the problem (in true XP style).  But in my tests I didn't intend this to work!  In fact at one point I was passing an array of doubles (which implements IList) to stop this kind of 'cheating'.  Unfortunately passing an array is open to a similar kind of abuse.

What is the easiest way to restrict the casting of an object?  I've revised the tests to use a class called RestrictedTypeProxy.  I am using it as follows to restrict the interface my ArrayList object is exposing...

            ArrayList arrayList = new ArrayList();
            RestrictedTypeProxy proxy = new RestrictedTypeProxy(arrayList, typeof(IList));
            IList list = (IList)proxy.GetTransparentProxy();

You can also pass any number of MarshalByRefObjects or interfaces.  For example...

            RestrictedTypeProxy proxy = new RestrictedTypeProxy(myOb, typeof(MBRO), typeof(IList), typeof(IDisposable));

You can see how it's implemented by scrolling to the bottom of the page here (oops, not any more).  I will need to use permalinks for historic challenges.  If you still want to see the code, it looks like Fabrice has found a way!

Code Blog

I've just uploaded a set of unit tests for a sorting algorithm.  Anyone is welcome to flesh out the failing stup implementation and make the tests pass.  You can compile the code and run the tests online.  Once all tests pass you are free to give your submission a title and post to the Code Blog.  To see other people's submissions you can subscribe to the feed.

At the moment the challenge is a bit obvious and boring.  Nevertheless it is interesting to see the different ways people go about solving the same problem.  If you have ideas for a future challenge, please post them here (preferably along with unit tests!).  I'm considering allowing people to offer bounty for problems they really need solving.

Enjoy.

Comment Spam

I may have just stumbled accross a solution for comment spam.  You can comment, but only when it builds and all tests pass...  ;o)

the /dev/null of the universe!

A funny little exchange on /.

Posted by Jamie Cansdale | with no comments
More Posts