Safe and Sound
February 2010
It was my pleasure to take part in the 200th Boagworld (bw200) yesterday. A marathon session that started with Bob, Paul and I waiting outside the locked barn keyless and cold until Dave, Stanton and Ryan came to the rescue...
In my mind the day was like a free one day, online conference with a brilliant lineup all sharing their time for free. There wasn't too rigid a schedule with guests in and out all the time either via skype or in person. However there was a general plan of 30minute sessions (expertly co-ordinated and organised by Ryan Taylor).
Each session was recorded and as far as I'm aware will be released by Marcus and Paul over the coming weeks.

Highlights for me included a relaxed, and seemingly extremely well read (if his bookshelf was anything to go by) Andy Clarke getting into a heated debate with Paul regarding browser support / progressive enhancement and some excellent food for thought from Drew Mclellan and Rachel Andrew in regard to e-commerce projects.
The only real lowlight was some rather unnecessary behaviour in the backchannel. Other than that it's a shame each guest was only on for 30minutues as there was some excellent content that could have taken up entire shows in their own right.
Thanks to the rotating host system I got to co-host a chat with Drew and Rachel on The Joel Test and to speak with Christian Heilmann about Yahoo's YQL.
The Joel test is an interesting one that allows teams to take a step back and guage how effectively they are operating. Covering questions on Source Control, bug tracking, scheduling and working conditions.
One of the tests that we didn't have time for was 'Do new candidates write code during their interview?' which for me is something that I've been wrestling with at Headscape (where we do ask for code to be created as part of the application process). Shortly I will be posting an article covering my thoughts on the matter (as encouraged by Emily).
Unfortunately I think there was a misunderstanding regarding the length of Christians session (being only half an hour instead of an hour) however I think it was one of the best sessions for takeaway action. The YQL demos that Christian had prepared showed us just how easily web apps and mashups can be created by standing on the shoulders of Yahoo. Allowing us to get down to the real functionally of our apps rather than worrying about the wiring of individual pieces across differing API boundaries. I urge you to take a look at the YQL Demos that Christian prepared.
All in all, a great day. Thanks to everyone involved (especially Cath for providing food for us all!
Some related bits and bobs
- A Flickr set of the show
- Some more photos from Stanton
- GooHooBi - An example of YQL usage to aggregate multiple search engines
- Christians YQL demo writeup
P.S. I'm still not sure Paul noticed the hijack of his about page throughout the day... did you?
Developer Day 8
February 2010
Another Developer Day over, another enthusiasm shot for the day job. Here's the usual breakdown:
| DeveloperDeveloperDeveloper: Speaker / Thoughts | |
|---|---|
| Mark Needham (ThoughtWorks) |
Not really what I had expected based on the title alone... After introducing functional programming as a language with first class functions (can be created during execution, passed/returned etc), immutability, lazy evaluation, recursion and pattern matching Mark proceeded to demo 'Transformational' instead of imperative thinking using the linq implementations of a variety of 'functional' principles: Map = Select, Filter = Where, Reduce ≅ Sum. Usage of such extensions on IEnuemerable allow code to be more declarative - with the statement of the desired result being specified as opposed to the exact process to undertake. Although Mark did make some good points in reference to realising linq can easily lead to duplication (reminding me of jquery selectors being used multiple times because they look small, irrespective of the actual work they are doing), the content generally had a low difficulty level feeling (which could have been enhanced perhaps by focusing more on the design patterns content that was briefly touched on), with a chunk of the questions at the end critiquing the examples rather than drilling down into the subject. |
| Mixing functional and object oriented approaches to programming in C# | |
| Andrea Magnorsky (Round Crisis) |
Probably my favourite talk of the day Andrea gave an excellent fast paced intro to Unit Testing using Xunit and Moq. With the example of testing an OrderService we saw how to use consistent, verbose naming of tests for clarity/ease of use and were reminded that a unit really does mean a small unit. For example multiple tests of the save method of OrderService were used to illustrate a first simple 'does not throw' test, through using a stub of an invalid object to check the 'if not valid return false' nature of save to using a mock of an email sender to check that a 'send email' call is sent. By using mocks and stubs the testing of the order service is contained only to the logic within the service and not to any of it's dependencies - any repository related aspects should be tested separately. The phase 'be super paranoid about your tests' enforced the idea that test code is no smaller matter than production code, and if anything should be treated even more thoroughly. A general rule given was that behaviour tests end in a Verify on Mock whereas state tests end in an Assert and that tests follow an Arrange, Action, Assert (or verify) flow. The final golden rules were: tests should not involve conditionals, should not depend on other tests and should not assess multiple expectations. Although pointed to during the talk it would be interesting to hear more about unit testing in the context of Test Driven Development. |
| Lessons learned on Unit Testing | |
| Jon Skeet (Google) |
Having previously seen Jon Skeet recreate linq to objects in 60mins this was undoubtedly going to be a good session. Jon covered the main 'newness' coming in C#4.0
|
| C# 4 | |
| Lunch Time | The Grok talks this year seemed a far bigger deal (with a large room and a lot of attendees). Some good tidbits included a demo of using T4 templates to generate code/sql/xaml in visual studio from Rob Blackmore and a run through of CodeRush Xpress by Rory Becker. |
| Grok Talks | |
| Simon Sabin (SQL Server Consultant) |
As with most developers I have been concerned by the use of ORM's such as Linq2Sql and EF in terms of the 'auto generated' sql that they produce. Simon allayed some of those concerns by running a number of test queries, using instrumentation such as 'SET STATISTICS TIME ON' to compare the differing sql between manually and EF created, with mostly good results. There were a few specific examples of weakness in EF1 however the speed of application construction must be balanced against the speed of direct ADO.NET queries (which vastly outperformed the ORM queries - with no overhead for mapping etc). A couple of important things to remember are that when you construct a sql statement you are asking SQL Server for the result not telling it exactly what to run and it will often reorgnise queries before execution. Additionally the old argument between stored procedures and text queries was touched upon with the only benefits really being the amount of text over the network and the security issues of allowing direct modification of tables. Performance is not an issue as compiled plans of text queries are cached in SQL. The underlying theme was to check your queries using tools such as SQL Server Profiler in order to hone your query performance (whether it be through direct SQL, EF, Linq2Sql, nHibernate..). |
| Entity Framework - How to stop your DBA from having a heart attack | |
| Barry Dorrans (Soon to be Microsoft) |
As Barry is soon to be moving to Microsoft in the states his talk was somewhat hijacked by the DDD team with various videos leading to a rather jovial atmosphere for the final talk of the day. The content itself was very factual rather than contextualised to the day to day in the sense that the presentation did not really go in to real world examples, prefering instead to describe the variety of encryption/hashing options available to developers.
|
| A developers guide to encryption | |
Overall some excellent content with useful take aways.
The Project52 Challenge
January 2010
During the end of December last year I, along with many others, somehow got caught up by the #p52 hashtag and, in true 'resolutions that I probably won't be able to keep' stylé, I took on the challenge. The idea is as follows:
The goal is to write at least 1 new article per week for 1 year.
http://project52.info
I'm kicking that off with a new article about useful .net dev resources and how to keep up to date. I've also finally made some good use of my free basecamp account by making a list of potential articles so I should be on my way for at least a few months. It's finding the time that could be tricky.
The idea has already 'persuaded' me to get some more functionality up on to cargowire. The categorisation of my posts is now exposed through url routes (e.g. http://cargowire.net/articles/tagged/general) and I will be tagging all my Project52 posts appropriately at: /articles/tagged/project52.
Additionally I've begun to add 'table of contents' links to the upper right of articles. Thus allowing skipping down the article. Commenting functionality is coming soon... I promise.
I'm also going to try and run a commenting #p52 alongside the article writing, as Yaili proposed.
Looking forward to a fun and productive 2010!
Cargowire MVC Series begins...
December 2009
A new post has just gone up over in the articles section. Now that I've migrated the cargowire codebase to .NET MVC I intend to release a few articles in relation to the process. The first is with regard to routing, particularly extensionless routes that match my pre-existing urls but use the new Routing capabilities of .NET MVC.
Overengineering and a lack of testing, the pitfalls of personal projects
November 2009
On this weeks show 'Content Negotiation' and browser testing
Ok, so yesterday I jumped the gun somewhat with the rather over ambitious:
asp.net MVC version of http://cargowire.net up now - pretty much the same (hopefully) fleshed out notes and added link to thebarn page
http://twitter.com/cargowire/status/6182546830
Inevitably this was followed by:
@cargowire heads up for you this is what I see in Safari 4 for http://cargowire.net OK in FF3.5 http://yfrog.com/4imo3p
http://twitter.com/porkandpaws/status/6183712464
Clearly I'd made three (or at least three of my) classic 'personal project for self only' mistakes:
- Overengineering
- Lack of testing
- Eagerness to get it live
I had set out to merely replace the backend of my previous .NET WebForms project (that used XSL/XML for view separation) with an implementation of asp.net/MVC. A fairly trival task, that along the way I expanded by virtue of being my own client and wanting to try out random things.
Being effectively an engine swap (I was even using the same XSL as well as javascript/css) I neglected to worry too much about browser rendering. After all, it was the same CSS that I'd tested before... surely all would be well.
The problem: Content Negotiation
My original cargowire implementation had the ability to serve different content types baked in. You could call most pages in the following ways (you still can now, try it):
- http://cargowire.net/articles (rendered html)
- http://cargowire.net/articles.html
- http://cargowire.net/articles.xml
- http://cargowire.net/articles.rss
I wanted to keep this functionality with the new asp.NET MVC version, however somewhere along the way I decided it would be a good idea to not only expose these different formats through varying file extensions but also respond to the HTTP Accept header that get sent with the request. This behaviour, similar to the respond_to method from Ruby On Rails, would allow multiple versions of the content to be requested easily.
The implementation was simple and based on my brief reading of the Http Accept header description.
// Pseudocode of the algorithm
format = request.extension
if exists(format) and haveViewFor(format)
return content as format
else
read in list of values from Accept header
sort the list of accept headers by quality first and original request order second
return content as the first format in the list that matches an available view
if no appropriate view found
return content as html
By attempting to find any possible view it allowed me to later add any format I like (json for example) just by adding the relevant view and all the plumbing would wire up.
All seemed well in Firefox, and after forgetting about this code and finishing the rest of the backend off, browser testing was irrelevant.. right?... I'd not changed any css, html or JS... I pushed live.
Why did Safari looks so funny?
During testing I'd been working with firefox, which, if you request an extensionless url, appears to send the following accept header (according to the live headers plugin):
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
So in my algorithm you'd get:
- text/html (default q = 1) - sorted before xhtml because requested first
- application/xhtml+xml (default q = 1)
- application/xml;q=0.9
- */*;q=0.8
In this scenario the code looks for a template for html, finds one and returns (ignoring the rest of the list).
When I saw the output from porkandpaws tweet it was immediately clear that he was seeing the XML output instead of html. A quick run in debug mode gave the following accept header from Safari 4:
Accept: application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
It would appear that if no extension is specified Safari will prioritise XML over XHTML. With application/xml requested before application/xhtml+xml and with both being assigned the default quality level 1 my algorithm assumed the client wanted the XML view and returned it!
The quick fix was to prioritise types containing 'html' before falling back to request order. This may not be a perfect solution, but lets be pragmatic, I'd only implemented this on a whim - no-one is actually using this site other than for the html or rss view.
Conclusion
To round up then, although overengineering and random play code is almost inevitable for the curious developer when working for themselves with no timescale, it doesn't excuse full testing and you can never rule out what any change, no matter how 'isolated', might effect.


http://twitter.com/porkandpaws/status/6183712464
