Our Silverlight Adventure

So, we finally took the plunge and started building out a new admin area of the site using Silverlight.

We’re tired of webforms and are using MVC on the front end, so we thought we’d improve the user experience by using Silverlight controls hosted in an MVC app for the Cms which is used by our editorial team.

I’ll document a few of the issues we ran in to starting out with Silverlight and how we have overcome them. They may not be the most ideal solutions, but the idea is to learn from our mistakes and improve.


MVC, Webforms & being pragmatic

It was interesting to see the announcement from dotnetnuke that they would not be migrating to MVC.

I’m familiar with dotnetnuke from a few years back when I was running The Website Shop and looking for a .net alternative to Joomla. It was awesome then and it still seems to be a strong option for those seeking an open source Cms platform.

The subsequent heated debate on Twitter and the blogosphere was amusing, as all such discussions are. I love the passion amongst the developer community.

Scott Guthrie provided some interesting insights, but what rang in my ears at the end of the article was the following:

“Syntax and APIs are rarely the most important thing anyway when it comes to development – problem solving, customer empathy/engagement, and the ability to stay focused and disciplined on a project are much more valuable.”

This is interesting, I’ve always felt that besides technical nous being pragmatic and resourceful are essential skills for a developer to have. Most of us work for businesses where we have to be sensitive and diplomatic to the needs of the business and such skills can really help with this.

As much as we strive to craft beautiful code and at times often sit in a near sublime trance, as our code becomes art and takes on a life and beauty of it’s own, the day to day practicalities are that we often have to leave technical debt or implement things in ways that we might not be completely comfortable with because of pressure from the business to get things done as quickly as possible.

We are in the process of creating a new “Experts” Q&A section for gurgle.com in MVC and we are already seeing enormous gains even whilst in development, as we refactor some of the common functionality to MVC. We’re quite sure that eventually we will build out the whole public facing site in MVC.

However, we also have a bespoke Cms that services the front end and is used internally by the editors and business administrators. The Cms has a whole bunch of ASP.NET web form controls and uses ASP.NET Ajax and the Ajax Control Toolkit. Since SEO and performance is not a priority on the backend, like the dotnetnuke team we’ve also decided to stick with web forms on the Cms, not because we believe one technology is better than the other but simply that at this point in time in the life of gurgle.com ASP.NET MVC is the better technology for the front end and ASP.NET web forms is more suited to the back end.

This is the best of both worlds for us, we get to improve our skill sets by using MVC whilst maintaining our existing ASP.NET Web Forms knowledge.

So ultimately being pragmatic about your choice of technology allows you to add value at many levels, and satisfy the priorities of others as well as yourselves.

Supress form submit in prototype

We’ve got a search field on our site that sits on all pages, when you enter text and hit ‘Go’ it takes you to the search results page.

Recently somebody highlighted a bug whereby hitting the enter key (which is a fairly natural action) submits the form back to itself and not to the search page!

This seems to be a common problem when you may have different actions on a single web form. So here’s a fix using the prototype library:

document.observe('dom:loaded', function() {
	var mybase = new base();
var base = function() {
    var self;

    return {
        init: function(c) {
        isObserved: function(element) {
            return ('_prototypeEventID' in $(element));
        setObservers: function() {
            self = this;
            Event.observe('btnSearch', 'click', this.search_submit);
            Event.observe('txtSearch', 'keypress', this.search_keypress);
        search_keypress: function(e) {
            if (!self.isObserved('form1')) 
                Event.observe('form1', 'submit', function() { return false; });
            var key = window.event ? window.event.keycode : e.which;
            if (key == 13 && $F('txtSearch'))
        search_submit: function() {
            location.href = '/tools_search.aspx?searchterm=' + $F('txtSearch');

Essentially I am observing every keypress on the Search input field, as it means the user is typing in a search term. On the first keypress I hook up an observer to the form’s submit event, which simply returns false when the user hits enter, thus suppressing the submit. The code can then continue and perform the search.

Culture ‘en’ is a neutral culture. It cannot be used in formatting and parsing and therefore cannot be set as the thread’s current culture.

Ran into this one today after a couple of Mac users reported a bug.

The application was having problems converting DateTime values.

When I looked at it I noticed that the users browser language was set to ‘en’.

I drilled down to the offending code:

public CultureInfo VisitorsCultureInfo
   get { 
     return CultureInfo.GetCultureInfo(

The developer has used the browser setting which equates to the CurrentUICulture, which as Peter Ritchie explains is incorrect.

.NET has the concept of a UI culture (for localization of resources) and an application culture (for the globalization of data).

Since we are working with dates (data) we should be using the CurrentCulture property.

The following article demonstrates a better approach.

So the bug has been resolved, and I can have a worry free weekend!

Here’s the fix:

public CultureInfo VisitorsCultureInfo
  get { return System.Threading.Thread.CurrentThread.CurrentCulture; }

Dynamic LINQ != Headache

Had a bit of a headache today when i realised I needed to dynamically sort the results of a Linq query – with Linq being type-safe at first it didn’t seem straightforward. Then Scott Guthrie came to my rescue and saved me rewriting the whole darn thing to use a stored procedure. Phew!

At the coalface

Gartner, the world’s leading information technology research and advisory company have revealed the top 10 technologies that they believe will change the world over the next four years:

1. Multicore and hybrid processors
2. Virtualization and fabric computing
3. Social networks and social software
4. Cloud computing and cloud/Web platforms
5. Web mashups
6. User Interface
7. Ubiquitous computing
8. Contextual computing
9. Augmented reality
10. Semantics

Right up there at number 3 – Social networks and social software.

I consider myself very lucky to be working in this area today and I really enjoy it. I remember working for an e-commerce start up at the turn of the decade and it’s got the same exciting feel to it – like we’re building the platforms today that people will be using for a good few years to come.

It was a really exciting time but the bubble did eventually burst and I moved on to more mundane business related activities which eventually bored me to death. This time, however, I’ve got a nice little salary protection plan and much clearer long term goals if things do go pear-shaped, suffice it to say I’m making hay whilst the sun shines!!!

Google AJAX Libraries API

This is pretty cool. We’re currently internationalising a couple of our social networking sites for the US and other international markets and I can see real benefits in using this approach, not least of which would be:

  • Caching can be done by Google… we don’t have to write and maintain additional code in our apps for this
  • Files are Gzipped
  • The files are hosted by Google which has a distributed CDN at various points around the world, so the files are “close” to the user (UK visitors get a copy from a UK based CDN, US Visitors from a US CDN, etc)
  • Because the libraries are hosted on the same URLs, if the user has used another application that uses this infrastructure, the file may already be cached on their local machine.
  • Google servers are able to deliver content fast!

Microsoft release source analysis tool

Microsoft have launched a new source analysis tool called StyleCop, similarly named to thier other analysis tool FxCop, but whereas FxCop is intended to check for good practice and standards against assemblies, StyleCop is more about checking good practice and standards in the source code itself.

Full details can be found on the MSDN Blog.

Initiatives towards encouraging well written, readable code are generally a good thing but it appears some already have some gripes with the standards MS are recommending with this tool – particularly with respect to the use of spaces over tabs – and the fact that, unlike FxCop, it is not possible to define one’s own rules, although having a set of common standards does imply one set of standards and not every “joe programmer’s” set of rules!

Also, it seems the tool simply reports the issues, which is as one would expect, and this has led some to propose that it should additionally perform a productivity function by automagically fixing all the issues as well.

It could be argued that in some respects it’s a good thing for a developer to return to thier code and manually correct these issues, since it might encourage a “right first time” approach in the future but with real world practicalities (deadlines et al!) I guess it’s a tough call to make.

Regardless, I’ll certainly be giving it a whirl – and correcting those issues …if I have time 😉

Update: 27/05/2008

It seems you can configure the tool to enforce or ignore specific rules.

Additionally when I took a look around the settings panel, under the “Settings Files” tab there are options to merge with additional settings files – as yet however I can find no documentation on how to create a settings file!

John Snow

John Snow
My office window looks out over the John Snow pub in Soho and recently our talented leader put a spot map up on the wall which John Snow had used to illustrate how cases of cholera were centred around the pump in Broadwick Street.

Snow’s study was a major event in the history of public health, and can be regarded as the founding event of the science of epidemiology.

A famous physician, who attended Queen Victoria, he was also widely recognised as a leading pioneer in the development of anaesthesia in Britain.

A fascinating tidbit of Soho history and an insight into a remarkable unsung British hero!

A new space race

WOW – I installed Microsoft’s WorldWide Telescope the other day and I’ve got to say it is absolutely awesome.

I always wanted a telescope but could never justify the cost when there are always more pressing priorities.

With WWT I can scan the entire night sky and zoom in on countless near and deep sky objects from NASA’s huge archive of images.

Initial impressions are that it beats the pants off of Google Sky but some commentators see this as the start of a different kind of space race that will herald in a new era in space research.

If you watch the Guided Tour on the Orion Nebula you can actually see protoplanetary discs forming around young stars, it’s that amazing you are able to see that level of detail right there in Orion’s belt – as if I wasn’t in awe enough when I looked up at the night sky this adds a whole new hypnotically beautiful dimension to it.

These increasingly powerful tools coupled with an increasing number of eyes looking outward has enormous potential for expanding our knowledge of our universe, and I always think it is really cool when technology enables your regular ‘joe’ to discover more about our fascinating arena of reality.