Software Craftsmanship

Most developers I’ve worked with would have come to me at some point and asked questions like:

  • What is the best way to implement this new feature?
  • What do you think of this design, is it good enough?

This to me indicates that software developers in general do take pride in their work and try to achieve the first part of the Manifesto for Software Craftsmanship:

Not only working software, but also well-crafted software

Given that most developers are competent enough to come up with good designs and implement them well with nice clean code and generally have the desire to do so, why is this rarely reflected in the resulting code?

The reason, I believe, is related to the second line from the same manifesto:

Not only responding to change, but also steadily adding value

The key word here being change. In contrast to my first observation, many developers when working with existing code will try and squeeze in their fix/feature and get out as quickly as possible. If they do come to me to talk about that change it’s just to grumble and complain about how hard it is to work with that code or how buggy it is.

The next time someone grumbles about some code they are working on I will remind them (or myself) that because they are now working on that code it is now their responsibility, it is up to them to make it better. If you’re not happy with the code you are working with, think about how the existing code could be changed to make your fix/feature easier to add.

If you’re not making the code base better, you are making it worse!

Tags: ,

Finally got my Android


I’ve had my HTC Hero for a few weeks now and I have to say it’s fantastic. I’ve never owned an iPhone or other smart phone so I can’t really give a proper review but I’ll make a few points.

The first thing that strikes me is that the user interface looks shiny and sleek but is also very practical.

I know other phones already do this but putting widgets on the home screen is a great way to customize the phone, you spend a lot less time scrolling through menus and lists. Apart from the standard clock/weather type widgets I use the twitter client widget and some of the on/off widgets for wifi, bluetooth, GPS etc.

One feature I really like is that when I add a contact I can select that person from my facebook and flickr friends, it will then use that persons facebook avatar and date of birth if available.

Although it comes with it’s own twitter application called Peep it doesn’t integrate twitter into the phone in the same way that it does with facebook and flickr. For example when I select a contact I can easily see their facebook/flickr updates and photos. I would’ve liked to see the same support for twitter (or even better, arbitrary person related data via third party plugins).

You could say a phone is only as good as the available apps, and this is a little problem for Irish users because paid apps are not yet available on the market place. But this is surely to change soon. In the meantime there are lots of free apps to play around with and it also comes with some nice apps pre installed like google maps and youtube.

With regard to using it in Ireland I have had no other problems except that O2 weren’t able to help setup the 3G settings. I eventually found the correct APN settings but MMS message are working for me at the moment, apparantly these settings work for both 3G and MMS but I haven’t tried them myself.

The only real problem I’ve had so far was with my home wifi, where I would connect successfully but about 30 seconds later it would drop the connection. I had to fiddle with my router’s wireless settings a lot until the phone’s wifi connection was more stable.

All the early reviews of the phone said that the phone was a bit sluggish, and I have to agree. While scrolling and sliding things around the screen it doesn’t always go smoothly.

But I’m using it quite happily and it seems that there is even a software update on the way that will help the performance.

Tags: , , ,

A limitation of shared hosting and a push toward cloud computing

Today I ran into one of the limitations of shared hosting.

I’ve been struggling for the last few weeks to handle large files in my application. I published to the server earlier this week but with no success. All my tests failed after 10 minutes with a ‘Request timed out’ error. I was testing with an 80mb file but with a slow broadband connection (thanks to Ice). I had increased the timeout and max request length for the upload handler like so in the web.config:

   <location path="Upload.mvc/Upload">
      <system.web>
         <httpRuntime  maxRequestLength="2097151" executionTimeout="10800" />
      </system.web>
   </location>

I ruled out any setting that I had control over, so the next step was to talk to my hoster, Blacknight, to see if they could help me out. They replied saying that they could not support the uploading of large files stating that:

It ties up too much system resources to upload huge files like that through asp and would cause problems for other users on the shared server.

Of course they’re right and I can’t really complain but it’s bitterly disappointing none the less.

For the foreseeable future, a couple of file uploads a month is all I require so I don’t want to pay for more expensive hosting packages. So back to the drawing board…

Cloud computing

I’m already using the Amazons S3 service for the storage of the images and I think I can upload directly from the client to S3. So I just need a high spec PC for a few minutes to process the files after the user has uploaded them. Once processed I will only ever have to deal with smaller versions or tiled sections. This looks like an ideal candidate for the Amazon Elastic Compute Cloud (EC2). Where I can pay by the hour for a high spec machine.

I was hoping to dip my toe into some cloud computing at some point but I didn’t want to be pushed. This is going to be a lot more work than I hoped and will need some effort just to cordinate between the web server, client machine and a cloud computer.

I haven’t decided on the final architecture yet, just thinking out loud, but looks like a lot of fun (and hard work) ahead…

Tags: , , , , ,

Handling multiple Web.config files in Visual Studio

I use different settings for my application when it is running on the live server and when it is running on my development machine. To manage this I name my config files using the target name like so:

  • Web.Debug.config
  • Web.Release.config

Adding the following to the project file will cause MSBuild to automatically copy the correct file to ‘Web.config’ when you build the project in Visual Studio. In my case the ‘BeforeBuild’ target was already in the project file but commented out, I just needed to add the copy task and related items.

<Target Name="BeforeBuild">
   <ItemGroup>
   <ConfigSourceFiles Include="Web.$(Configuration).config" />
   <ConfigDestinationFiles Include="Web.config" />
   </ItemGroup>
   <Copy
      SourceFiles="@(ConfigSourceFiles)"
      DestinationFiles="@(ConfigDestinationFiles)"
   />
</Target>

So I select the right target from the toolbar and build/publish and the correct settings are used.

Where possible, to avoid duplicating settings, I create separate config files and point the main config files at it using the configSource attribute. For example the page settings for debug and release are the same so my pages element in both files look like this:

   <pages configSource="Configuration\System.Web\pages.config" />

Before implementing this I was manually changing or copying the config files before deploying to my server, so I hope this will help someone else save a bit of time.

Tags: , ,

Not mocking the HttpContext?

Someone asked me a question recently about mocking, and I had to say I didn’t have much experience with it. I found this answer a bit odd myself as I’ve been doing a lot of TDD with an ASP.Net MVC application. I’d seen lots of people talking about mocking the HttpContext and wondered “Why haven’t I had to do this?”.

The first time I started TDD, I was working on converting an existing ASP.Net application to ASP.Net MVC. Most of my controller actions checked the current security principle in the context, so I immediately ran into problems when trying to test these.
I didn’t know much about MVC or TDD so used what I did know. I knew about a powerful component of MVC called an action invoker, that could be overridden to handle some parameter stuff. I found that I could easily create an ActionInvoker that would populate parameters of a certain type (namely IPrincipal) using the following code:
public class ActionInvoker : ControllerActionInvoker
{
   protected override object GetParameterValue(System.Reflection.ParameterInfo parameterInfo)
   {
      if (parameterInfo.ParameterType == typeof(IPrincipal))
         return HttpContext.Current.User;

      return base.GetParameterValue(parameterInfo);
   }
}

And put the following into my controller constructors:
public MyController()
{
   ActionInvoker = new ActionInvokers.ActionInvoker();
}
This made it easy to test my controller actions. I just needed to mock a simple IPrincipal. I used a similar solution when my file upload controller needed access to HttpContext.Current.Request.Files.
At the moment my code only depends on a few simple objects that come from the HttpContext and not the context itself. Surely this is better, if not please comment. I’m going to change the above to conform with everyone else by mocking the HttpContext but the only reason I see for doing this, is that the above action invoker is not testable. Is this the only reason?
Before you point it out to me, I have recently moved most of my security code into AuthorizeAttributes. Now my unit tests for invalid calls (security wise) to controller actions all fail but that’s for a future post.

Tags: , ,

T-mobile G1 (Google's Android phone) in Ireland?

It’s just the nerdiest geekiest phone ever. The operating is open source plus check out the cool logo. I just have to get one.

Sadly it’s not available in Ireland. People who have imported the phones and unlocked them have reported some problems when trying to get the full use from the network. So I don’t think I will chance doing this.

I read today however, that there is an “Android Dev Phone 1″ available “outside of T-Mobile geographies”. It’s currently available in 18 countries, Ireland is not mentioned yet but it looks more likely to be available here than from one of the Irish phone companies.

Now it doesn’t actually say that it is the same hardware as the T-Mobile G1 but the specs look similar and other blogs are saying it’s the same. It’s available from the Android Market so I went for a closer look.

The Android Market is not as open as I was expecting. It cost me 20 euros just to take a peek at “more information about obtaining an Android Dev Phone 1 device”. Plus the only way to pay was via google checkout, no pay-pal option.

So what did I find out from the Android Market, well nothing. “Your Registration to the Android Market is still being processed”. Looks like the only thing that’s open is the Operating system, everything else is locked tight. I’ll keep you updated as I find out more.

BTW, Google had a little UI blunder in their checkout form. When you select Ireland they have a drop down list of the counties which I thought was quite nice. Normally when I see a list of counties I just type L-I to bring to me Limerick, very easy. But this time it didn’t work, I had to type C-O-DOT-SPACE-L-I as in “Co. Limerick”. Some times attention to detail can be a bad thing.

Tags: , , , ,

What's up with the Tadmap project?

If you’ve been following the Tadmap blog then you might be wondering why there haven’t been any updates since November. Well here’s why.

Before Christmas I decided to try out the new ASP.Net MVC framework, for no other reason than wanting to learn more about it. My initial impression was that it would be ideal for Tadmap, so I decided to go for it. The change over meant refactoring all the pages I already had into controller and views, and I got 90% there very quickley. As I had never used MVC before I started following Rob Conery’s MVC Storefront series to make sure I was doing things right. This may or may not have been a mistake.

First, he was using a fancy new version of the Repository pattern which I liked the look of very much, this lead to even more refactoring and learning more about LINQ on the way.

I tried to ignore the Test Driven Development aspect of what Rob was doing, but eventually I downloaded Nunit just to try my hands at writing an automated test. Straight away I was hooked on TDD. I tried limiting TDD to just new code but to make the new code testable meant refactoring the old code to reduce dependencies.

It’s taken a lot longer then I wanted but I am having a lot of fun doing it. My code is clean and loosely coupled and I have over a hundred unit tests and a bunch of integration tests that I can fire with one click.

Even though I have no boss and as yet no users, I have still run into the age old problem of doing it right versus getting it done. There is the ultimate balance to be made between making things perfect while achieving the goals and real world features that help our moral and motivation. It’s starting to bother me that I haven’t been able to add any new features in over a month.

So in the next few weeks I hope to get an, albeit imperfect, ASP.Net MVC version of the application up on the live server. I’ll then be in a position to iron out the last few post refactoring bugs or implement a cool new feature when I need the motivation to keep going.

Tags: , , ,

More blogging in 2009

It’s a new year, a time to start those good habits again. One thing I want to start doing this year is to write more blog posts. Four blog posts in November, that’s pretty good going for me but then nothing in December. The reason I hesitate when it comes to publishing stuff is that I’m not very good at writing. But that’s not going to change with out some practice.
The other reason not to publish something is the feeling that it’s not worth saying unless it’s going to contribute something that other people actually want. But as you can see from this post, I don’t care about that anymore.  I’m just going to say stuff and get things off my chest.
So what am I going to write about? I will try to keep it somewhat technical in nature. Professionally I work with ASP.Net 2.0 but on my Tadmap project I’m getting to work with some cool new stuff like C# 3.0, ASP.net MVC, LINQ and Test Driven Development. All of which may be food for future blog posts.
As you can see on my blog page, I have added my twitter updates. I’ve had a twitter account for a while now but just started using it lately. This is just another way for me to practice writing. I think this whole twitter lark maybe just a fad but I’ll give it go for while and see what happens.

Tags: , , ,

ASP.Net MVC on Blacknight

Update: SP1 is now installed for ASP.Net 3.5. So now the only DLL you need to upload is ‘System.Web.Mvc.dll’.

I was reading a little bit about the new ASP.Net MVC stuff. I think it would be ideal for my Tadmap (image hosting) project. Before I started any major development re-work I needed to check that my hosting provider, Blacknight, could host it.
So I uploaded the sample MVC application. Of course it didn’t work at first but I don’t give up that easily and it is now up and running. I think the following steps will work for anybody else trying the same.
As Blacknight do not have SP1 installed for ASP.Net 3.5 you have to upload the new DLLs when you deploy. Simple instructions can be found here, Bin Deploying ASP.NET MVC.

My windows account on Blacknight is using IIS 6.0 which does not automatically support MVC. In order to handle URLs the MVC way you will need to follow the instructions here, ASP.NET MVC on IIS 6 Walkthrough. Basically, you just need to grab the code for the Global.asax.cs file and add a ‘.mvc’ file mapping using your Blacknight control panel.
To add the file mapping, just go to the ‘Web’ tab of your domain and add ‘mvc’ to the ASP.Net 2 mappings. It should look like the image below and make sure that ‘Script Engine’ is ‘On’ and ‘Verify File Exists’ is ‘Off’.

One small (cosmetic) problem is that the URLs aren’t as clean as they should be because the ‘mvc’ extension is needed. So the URL for the About action of the Home controller that should look like ‘http://trevorpower.com/Home/About‘ instead looks like ‘http://trevorpower.com/Home.mvc/About‘. I have seen solutions to this problem as well but that’s for another day. Right now I have the not so small task of converting an existing ASP.Net application to an ASP.Net MVC application.

Tags: , ,

Tadmap – Image Hosting for Map Collectors

One of my interests is in early maps. I don’t have a big collection or anything but I would like to be able to browse them on my computer or show them to other people. One of my hobby projects is to provide a website that does just that.

The technical aspects of developing Tadmap I will probably write about on this blog, but I am also writing on the Tadmap blog if you are interested in learning more about it.

Tags: , ,