This is my personal blog. The views expressed on these pages are mine alone and not those of my employer.

Saturday, 19 February 2011

Keeping it simple - stupid

Einstein once said "Everything should be made as simple as possible, but not simpler" which couldn't apply any more to physics as it does modern software development.

You see - modern software development is brimming full of abstractions - which exist solely to provide simplification through hiding complexity.

These abstractions tend to come along with 'buzz word' names, here's just a handful:

- Web Services
- ASP.NET Web Forms
- User Controls

These are all 'cool' words to find on anyones CV, and asking a software developer about each would result in volumes spoken.  However at the end of the day all of these boil down to abstracting the underlying messages being passed across a network.  Imagine having to piece together each HTTP packet, adding the headers, and populating its payload - it would take an age to build anything, never mind a decent website, user control or web service - which is the problem abstraction solves.

However abstractions are very limited in their scope, and it's too easy for the non-experienced to try and abstract too much.  Abstractions keep things simple, but applied too wide they make things simpler.  And we know good old Einstein wouldn't be impressed with that.

To illustrate this point I'd like to describe something I recently experienced.  A requirement of ours was to provide nightly backups across the internet, between two separate systems. To achieve this the following would take place:
  • The backup would be uploaded over FTP
  • A message would be sent to the recipient of the backup when complete (to allow it to process the backup)
The developer in charge decided the message after the upload was complete should be sent via a method call to a web service, which would also pass the hash of the uploaded file so it could be verified.  There was a number of problems getting this set up, and while the FTP side of things worked perfectly, the web service didn't.

The point I'm making is that a web service is an abstraction over HTTP, and is complete overkill for a simple method call.  A much better (and simpler) way would be to create a page who's URL allowed the hash to be passed in as a variable.  Which would in turn carry out the same actions as the web service.

Doing it this way allows a number of benefits over the web service option:
  • Any machine connected to the internet could send the 'completed' message as there is no reliance on the .net framework
  • A lot of overhead has been removed
  • There no need to install, debug, and mess around with web service way of doing things
The developer involved had the notion that using a web service is some how more secure, which just sounds downright dangerous to me.  If you've got an open web service, anyone can play around with it, but that's because I understand that its just abstracting a bunch of HTTP calls.

I therefore urge all software developers out there to think before you type anything, remember this is what a specification is for!  Are you trying to abstract something which is already simple?  You wouldn't nail a picture to the wall with a sledgehammer, would you?

Tuesday, 8 February 2011

ASP.NET ComboBox

Want a ComboBox for your ASP.NET application?  One that works? Cross browser? Well you're in luck.

A ComboBox is a control that displays a TextBox combined with a ListBox - which enables the user to either select an item from the list or type their own.  They have many uses - as I'm sure most of you are aware.

I've always had a hard time trying to understand why Microsoft haven't provided a decent implementation of a ComboBox for ASP.NET applications.  They have tried - and its included in the AJAX Control Toolkit - but its pretty darn useless if you ask me.

Don't get me wrong, there are plenty of permutations of ComboBox out there and as the adage goes "great programmers don't write what can be stolen", but the best ones aren't free and I just couldn't justify paying for something that should be.  So I got to work and made my own:




Pretty nice isn't it?

Features of the control:
  • Nice and smooth sliding action
  • Its lightweight and simple
  • Renders in all browsers
It uses jQuery - so you'll have to include a script tag wherever you use it, I'm using this one kindly hosted at google:

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js">

Overall it took me around 2 simple hours to create, so why after 9 years since the ASP.NET framework has been released can Microsoft not provide a decent clone of the Windows ComboBox?

By all means my version is no way finished - it was created it to make a point.  However by providing the source on here I've hopefully filled a gap in the ASP.NET control selection.  I know that by storing it on here I should hopefully never lose it, and also allow others to use as they wish.

A couple of things you may want to implement into this control:

  • Remove the unnecessary postback when selecting an element using Javascript
  • Allow the height of the listbox to change dynamically depending on its contents
  • Add a load more methods (perhaps to bring it in line with the AJAX Control Toolkit)
  • Ajaxify it - what isn't these days?

I'm providing it as a Visual Studio 2008 solution so you can fire it up straight away, however it's trivial to open in any version.  You can grab it here.  I must say I'm quite proud of it.

All in all its a simple control - but it works perfectly for what I need.  Please download the source and modify as you wish, however I'd be grateful if you cited me as the source. Perhaps even Microsoft will pick up on it (I can wish).