Skip to main content

Posts

Showing posts from 2012

Looking forward to 2013

First and foremost, the biggest change in 2013 is that I will be responsible for and managing the development team. To help the team with the challenges we will face in 2013 I will need to stay hand on too, so that should make time management critical just to make sure I can personally fit it all in. This will probably be the biggest challenge I have faced in the last few years and something that I'm looking forward to getting started with.Another change for 2013 will be refining our agile process. For the 2nd half of 2012 we followed a scrum methodology, successfully developing and deploying an MVC replacement for an old ASP legacy application. Feedback from the technical teams resulted in us modifying the process, removing task hour estimation from the sprint planning session with no measurable negative effect. Additional feedback from the business indicated that sprints were causing some friction when defining stories and planning releases. The 6-9 month development cycles…

Review of 2012

2012 has been a full-on year with lots of change. I started the year in my previous role, preparing for a transition into a newly created role of "Solution Architect"; moving away from both day to day coding and purely concentrating on .NET applications / systems. It sounded a really interesting challenge but another opportunity presented itself working for my current company in another newly created role of "Technical Team Lead". It was a hands-on development role, leading a team of 3 developers bringing a large business critical application in-house and helping to roll out scrum and other processes (such as TDD/BDD, Continuous Integration, etc.) to the business and team.The very first challenge was the knowledge transfer sessions for the "out-sourced" application, which had been designed and developed by one company and then the maintenance passed onto a second company. It's probably fair to say that the code has grown organically rather than bei…

VS2012 does not support Silverlight 3.0

Not sure that this post really needs anything more than the title. If you are upgrading a Silverlight project from VS2008 or VS2010 be aware that VS2012 only supports versions 4 & 5 of Silverlight. If you need to update the solution / projects to use them in VS2012 I'd recommend upgrading to at least Silverlight 4 first in your existing Visual Studio and then once it's working upgrade the solution/projects to VS2012 so you're only tackling one set of issues at a time.

Upgrading a TeamCity build from VS2008 to VS2012 and using NuGet

We've recently upgraded to Visual Studio 2012 from VS2008 and switched over to using NuGet rather than direct project references for our third party tools. Everything worked as planned until we checked the solution into source control and the personal build for TeamCity kicked off. Almost straight away the build fell over with the following error message:D:\TeamCity\buildAgent\work\e6ae794aab32547b\.nuget\nuget.targets(102, 9): error MSB4067: The element <ParameterGroup> beneath element <UsingTask> is unrecognized. Project BJ.Core.sln failed. Our projects were still targeting .NET 3.5 but to fix the problem we needed to update the visual studio version in the build configurationNote: we were are using Visual Studio 2012, but our Team City server is currently hosted on a 2003 Server O/S instance so we must select the VS2010 option in our build configuration (VS2012 option only works on 2008 Server and higher due to .NET 4.5 limitation).

Can't target .NET 3.5 after upgrading a Visual Studio 2008 solution to 2012

I ran into an interesting problem today when upgrading a visual studio 2008 project to visual studio 2012, whilst trying to leave the targeted framework to .NET 3.5. Each time I tried to open the solution all my test projects automatically upgraded to .NET 4.0 regardless of what I did. It was impossible to downgrade the project using either the project property page or manually editing the project file. I'd make the change and then reload the project, a project conversion report would be shown and the project was back to targeting 4.0 again.After a little more digging around I noticed that it was only my test projects that were doing this, all the other class libraries, etc. were perfectly happy targeting 3.5. After a little more experimentation I isolated this to the project type guids section, if I removed this from the project definition then I could re-target my unit test project at v3.5 and everything was happy. Note: As the linked blog post indicates, you might lose the…

Agile Delivery Experiences

I'm now in my second role in which I've had chance to introduce agile working practices to the team. In both roles the projects and applications developed under scrum have been successfully shipped and accepted by the business. The success of the deliveries has been measured by:Functionality: The early visibility the business gained through the end of sprint demonstrations made sure that all the functionality the team developed stayed on track and provided exactly what the business wanted. There were no nasty surprises once the final code was shipped!On Time: It is generally agreed that you can only have two of the following: quality, functionality and/or a "business set" ship date. The hardest lesson for a business to learn is that if it wants a set amount of functionality by a set ship date, then the only thing that can be modified by the team to meet the expectations is quality. Luckily in both instances everyone agreed that quality shouldn't be compromise…

Do "Task Hours" add anything in Scrum (Agile)?

What do task hours add to the overall process in scrum?This was a question that has arisen from all team members in both instances that I've helped teams switch over to scrum. The benefits of artifacts like the comparative story point estimation, the 2 week sprints, stand-ups and the end of sprint demo have been self evident to the team, but as one I think every team member has expressed dismay when it comes to task planning and estimating each task in hours. Left unchecked there is a natural tendency for people to actually begin to dread the start of each sprint purely due to the task planning session.In my current role we've been lucky to investigate this further as a team.The team sat down to discuss the problems it was experiencing with estimating tasks in hours and the following common themes appeared:It is hard: Maybe it shouldn't be, but time estimation is hard! Story points are comparative and abstracted making them easier to determine, but time estimate is gen…

Website Update

It's been over 2 years in it's current form and I really must get around to updating my website. As you can see, I went for a really retro "early days of the web" approach; possibly even with the caveat that it's best viewed in a text only browser. So moving on, time for an update - I've not drawn up any designs, so that should be interesting but the site will probably just be an aggregation of me on the web. Think I'm going to write the first version in .NET, using MVC4 and Razor and whilst I'm not sure that there will be much demand, I'll host the code on my github account So watch this space for updates!

Add NuGet Reference in Resharper

Today Jetbrains announced on their blog that they've released a resharper nuget package that will obtain project references via nuget, rather than making direct references to the locally installed code.As we are currently in the early stages of transitioning from VS2008 to VS2012 we aren't ready to start using NuGet(*) but I think I'll be grabbing this plugin for when we do. (*) In my last role we were using VS2010 and making heavy use of NuGet so can't wait to get back into being able to use it again!

Project Euler

Over the past couple of years I keep on coming back to Project Euler, it's nice when you just want a quick challenge, or to try your maths skills. It's highlighted how rusty some of my concepts were, and I've learnt a whole load of new ones along the way. I really like the way that the example problem given is quite quick to determine using brute force, but the desired answer always needs a more considered approach.I've just completed problem 26, to determine value of d (1/d) where d < 1,000 and resulted in the largest recurring cycle of the decimal fraction. My first (working) solution completed the task in 2.8 seconds, well within the proposed ideal time frame. What's really helpful is then reading through the forum of previous solutions you can pick up some ideas that start to bring the entire process down to under a second!You can see my progress in the graphic on the right hand side, or can check my progress on the project euler site.

To code review or not to code review?

There are many articles on the web about how to do good code reviews, with mostly all of them either discussing their merits or how to obtain maximum value from them.In a new role I've recently helped introduce and roll out the agile process and to start with as part of each story we always added a task to "code review" all work. We made sure that differences from source control were used to make sure only the changes made were reviewed, made sure that everyone had chance to partake in reviews so it wasn't just one or two people providing all the feedback on the other team members work. It worked well, the reviews were productive and provided really good feedback for everyone.But there was something about them that didn't feel right for the entire team, but it was the sprint planning process of tasking the stories that gave us the answer to what was bothering us. For every story we added the code review task to the END of the story, which of course by it's…

Reducing code noise for argument checking / assignment

Leading on from the previous blog post on reducing code noise when checking for null parameters, these help functions can be utilised to further reduce code noise that generally occurs in class constructors. Most constructors are purely made up of the following duplicated checking / assignment code. public class MyClass { private readonlyobject var1; private readonlyobject var1; public MyClass(object arg1, object arg2) { if (arg1 == null) { throw newArgumentNullException("arg1"); } if (arg2 == null) { throw newArgumentNullException("arg2"); } this.var1 = arg1; this.var2 = arg2; } Again putting together a small helper function, making use of the previous Throw class can remove 90% of the previous argument checking / assignment code resulting in: public class MyClass { private readonlyobject var1; private readonlyobject var1; public MyClass(object arg1, object arg2) { this.var1 = ReturnParameter.OrThrowIfNull(arg1, "arg1"); this.var2 = ReturnParameter.OrThrowIfNull(arg2, "…

Reducing code noise when checking for null parameters

The problem with writing defensive fail early code, it doesn't take long before methods are 70% argument checking, 30% logic: public void Method(object arg1, object arg2) { if (arg1 == null) { throw newArgumentNullException("arg1"); } if (arg2 == null) { throw newArgumentNullException("arg2"); } ... ... ... } Code contracts can be a great way to move code out of the method body, but how can you clean up the code just through traditional refactoring? For the last few projects I've worked on, I've been using a small helper class that abstracts all the conditional code out, leaving just a single line call for each check you need. public void Method(object arg1, object arg2) { Throw.IfNull(arg1, "arg1"); Throw.IfNull(arg2, "arg2"); ... ... ... } String parameter checking can wrap up even more conditional logic. The following code throws an ArgumentNullException if the string is null, or just an ArgumentException if it is empty or whitespace. Throw.IfNullEmp…

Blogs as an indication of job satisfaction?

When was the last time you updated your blog?Have you done anything lately that was worth blogging about?These are all questions that have been rattling around my head recently. I've experienced it myself, I've seen it via my colleagues. When people are working on interesting stuff, focused on solving clearly defined business goals, their blogs are full of detail and insightful to read! If the business is losing or has lost direction, blogs become an attempt to stay focused and continue honing skills but slowly over time the drain of the working day drags the blog content down to just notes or, worse still, silence.I'm beginning to see the worth of a blog as a litmus test on job satisfaction - a stagnating or random blog probably indicates a day job that is doing something similar! Many posts (regardless of the stats) probably indicates a full on and enjoyable day job focused on solving tangible business goalsThere is probably a good argument that a job shouldn't d…

Project Euler #24

I'm trying to start up on project Euler again, one thing I do like is that it highlights how poor some of my maths knowledge actually is. Neither school or college covered many of these algorithms; which is bit of a surprise given that I did a four year mechanical apprenticeship with applied mathematics.....still never too late to learnSo I (re)started on problem 24 which read:A permutation is an ordered arrangement of objects. For example, 3124 is one possible permutation of the digits 1, 2, 3 and 4. If all of the permutations are listed numerically or alphabetically, we call it lexicographic order. The lexicographic permutations of 0, 1 and 2 are:012 021 102 120 201 210What is the millionth lexicographic permutation of the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9?I usually start with a brute force attack on the problem, using TDD and the supplied example to verify the output. This worked nicely for the given example, but even on modern computing power I couldn't ge…

VS2012/.NET4.5 and Server 2003

Just a word of warning:Windows NT and Windows Server 2003 do not support .NET 4.5 - you can not install the framework onto these systems.So if you are building in visual studio 2012 and have to support Server 2003 (or earlier) then you must remember to target .NET4.0 (or lower) in your project(s) otherwise you will not be able to run them on the target system. That would be a really bad thing to find at the end of the project; another good reason to implement continuous integration/deployment into any project from the outset (and deploy to an instance/server that represents the target o/s)

How to set the background colour of the paper in Raphael

I've started playing with the JavaScript SVG library RaphaelJS. It looks a really nice library but the very first hurdle I came across was how to set the background colour of the paper. There didn't seem to be any help in the documentation and trying 'paper.attr("fill", "#f00");' resulted in the error Uncaught TypeError: Object #<a> has no method 'attr'. A less than optimal solution might be to create a rectangle on the paper that is the same size as the paper and fill that with the desired colour. But then all objects would need to sit on top of that element and it just feels messy.Looking for a different approach I fired up developer tools in the browser and inspected the HTML, it was at this point I realised the solution was probably pretty simple. Using a style sheet and setting a CSS background colour for the <SVG> tag did exactly what I wanted; it sets the background colour nicely and doesn't need any additional el…

Breaking JavaScript code down into components

Following on from my original post of learning how to put JavaScript together it's been a really productive week. Have I managed to write JavaScript that's easy to test? No, but I've wrapped up some reasonably complex logic into a component that can have some of it's functionality tested!At the moment I've settled on QUnit as my JS unit testing framework and have a couple of tests verifying the default values of exposed properties - these are currently exposed as functions as I've wrapped up the variables in a closure to make them read only. Not sure if JavaScript even has the concept of a read only property in a form similar to C#. When calling the component in test conditions I've also been overwriting functions on the injected underscore library that failed due to a null/undefined reference - so not really mocking yet. The first issue I ran into was that I was pre-compiling the templates and these were defined inside script blocks of the calling ASP.N…

Create & inserting GUIDs in Visual Studio

If you're using WIX and you're adding components to the product file by hand then you've probably found yourself creating and cutting/pasting a lot of GUIDs which can be a real pain and productivity killer. There is the "Create GUID" menu option under tools but that still requires calling and then cutting / pasting. The other day one of other members on our team came up with these steps to create a macro that will create and insert a new GUID and can be bound to a key board short cut.Go to Tools – Macros – Macro Explorer and paste the following into a module:Sub InsertGuid() Dim objTextSelection As TextSelection objTextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection) objTextSelection.Text = System.Guid.NewGuid.ToString("D").ToUpperInvariant End Sub Then assign it a keyboard shortcut through Tools – Environment/Keyboard, you can generate a GUID in-place with a simple keyboard shortcut.No more copy/paste

Learning how to put JavaScript together properly

After many years of trial and error / practise I feel fairly happy that I can write clean, testable .NET / C# code, which is free of any external dependencies which traditionally make unit testing harder. It's fair to say that I'm convert to TDD; having implemented it on two separate commercial projects and seen the benefits of the improved maintainability of the code base over time.But what about Javascript? Thanks to Selenium and Specflow the functionality of those websites is pretty well tested and by default that includes any JavaScript that may be referenced in the UI tests that are run. But that's not the same as having clean testable JavaScript. Those websites have typically included a mixture of JavaScript defined in-line as well as held separately within JS files. Most functionality has been provided by individual functions attached to events and any communication introduced by coupling of functions and/or attaching attributes to FORM elements. AJAX calls an…

Handling the orientation of screens in web pages

As part of responsive design a web page should react to the device it is being displayed on and make the most of the available screen real estate accordingly. With the advent of HTML5 & CSS3 the media tag for stylesheet links has been extended to cope with minimum screen heights and widths. It has also been extended to include "orientation", the following header block correctly loads/references the relevant stylesheet for the orientation of the website you are viewing.<linkrel="stylesheet" media="all and (orientation:portrait)" href="portrait.css"> <linkrel="stylesheet" media="all and (orientation:landscape)" href="landscape.css"> This is functionality is live & dynamic; changing the orientation of an IPad whilst viewing a page that implements the above CSS will correctly change the CSS references depending upon whether you are now viewing the page in landscape or portrait. This also works on LC…

Unit Testing Workflow Code Activities - Part 1

When I first started looking into Windows Workflow one of the first things that I liked about it was how it separated responsibilities. The workflow was responsible for handling the procedural logic with all it's conditional statements, etc. Whilst individual code activities could be written to handle the business logic processing; created in small easily re-usable components. To try and realise my original perception this series of blog posts will cover the unit testing of bespoke code activities; broken down into: Part One: Unit testing a code activity with a (generic) cast return type (this post)Part Two: Unit testing a code activity that assigns it's (multiple) output to "OutArguments" (Not yet written)So to make a start consider the following really basic code activity; it expects an InArgument<string> of "Input" and returns a string containing the processed output; in this case a reverse copy of the value held in "Input".namespace Ex…

Windows Workflow: Re-introducing old anti-patterns?

As part of my day job I've been experimenting with Windows Workflow in both modifying the existing TFS2010 build templates and as a way of controlling the process flow in our new suite of applications. On the most part I've been really impressed; when you sit in a process workshop watching the business users mapping the existing steps out on a white board (or even a wall) it is quickly apparent that showing them a similar flow should hold significant benefits. Gherkin goes some way towards creating a syntax/language that works for both technical and non-technical people, but it is a test language verifying the application is working as intended - you don't write the process itself in gherkin. We've also found (from experience) that gherkin has a reasonable learning curve for both technical and non-technical users; whilst most people seem to find it easy to relate to the visual element of workflow with little or no training.But as I opened I've been impressed for …

TFS2010: Publishing solution projects to their own directories

When looking to automate a TFS2010 build one of the first issues that most people seem to encounter is that all the binaries of each project in a solution end up in the same "bin" directory. The forum post TFS 2010 BUILD SERVER: Can not keep folder tree in the drop location ? details the solution; which is changes to both the CSPROJ file and the workflow template that is called by your build. Note: each CSPROJ file in your project needs to be updated as the workflow loops through the solution finding all the referenced projects.. The answer in the forum post has everything about what is needed but not why, which can be a bit confusing if you're just starting out with TFS / workflow. The image to the left is the section of the workflow that is changed. The workflow variable "OutputDirectory" is defined within the scope of "Compile and Test for configuration" (highlighted in green). The value of "outputDirectory" is assigned (highlighted i…

Improving “Boiler Plate” Data-Reader Code – Part 5

In this post we will extend the query functionality to handle stored procedures with parameters. To do this we need to create a new query type interface with an example implementation: public interfaceIDefineAStoredProcedureQuery : IQuery { string StoredProcName { get; } IList<SqlParameter> Parameters { get; } } public classGetCustomersByFirstName : IDefineAStoredProcedureQuery { public GetCustomersByFirstName(string firstName) { this.Parameters = newList<SqlParameter> { newSqlParameter("FirstName", firstName) }; } public string StoredProcName { get { return "GetCustomersByFirstName"; } } publicIList<SqlParameter> Parameters { get; private set; } } Now that we have the ability to create stored procedure queries we need something to handle them. To do this we need a concrete implementation of the interface "IHandleAQuery":public classStoredProcedureQueryHandler : IHandleAQuery { public void Assign(SqlCommand command, IQuery query) { var castQuery = query…

Improving “Boiler Plate” Data-Reader Code – Part 4

In part 3 we created a SQL repository object that took a populated instance of IQuery to select/return an enumerable list of objects. A limitation of the repository was that the query had to be text based, it couldn't handle stored procedures and/or parameters. By incorporating an abstract factory pattern we can extend the functionality to handle different types of query.The original code inside "SqlRepository.Get(...)" needs to be changed from:using (var command = connection.CreateCommand()) { command.CommandText = query.Text; connection.Open(); To:using (var command = connection.CreateCommand()) { var handler = QueryHandlerFactory.Create(query); handler.Assign(command, query); connection.Open(); The static factory class takes an instance of IQuery and determines which "query handler" to return depending upon the additional interface that the "passed in" query implements. This is implemented via the following code:public static classQueryHandlerFactory { publ…

Improving “Boiler Plate” Data-Reader Code – Part 3

In Part 1 of this series we started with a basic Data-Reader / SQL Connection/Command pattern and illustrated how it is possible to abstract the parsing of the Data Reader into a standalone object that can be fully unit tested in isolation of the calling code. In Part 2 of the series we made a very simple optimisation to the “DataReader” convertor and updated the tests to capture/verify the changes.In part 3 of the series we put this all together into a repository pattern to create a reusable and testable data access layer. The first step is to create an interface for the repository.namespace DataAccess.Example { using System.Collections.Generic; using System.Data.BoilerPlate; public interfaceIRespository { IEnumerable<TEntity> Get(IQuery query, IConvertDataReader<TEntity> dataReaderConvertor); } } The intent implied by the interface is that "Get" will be responsible for returning an enumerable list of a generic. To do this we pass in an implementation of IQuery and an …

Managing your dependencies in NuGet

When creating NuGet packages, how do you define your dependencies?If you're using the default setting of 'x' version or newer are you sure that all future versions of the dependency will work with the current version of your code? I'm not sure many people would be happy saying yes to that question but most NuGet packages are deployed with the default setting for their dependencies. Using a typical dependency, Log4Net, you might deploy a package today referencing the current build and everything's fine. But in a month or two's time there may be an update to Log4Net deployed that contains breaking changes. From that point on anyone that grabs your package from NuGet will find that it no longer works - instead of the version of Log4Net you developed against, they are now getting the latest version that breaks your code.Whilst it may be more work, the safer option may be to use the version "range" option for managing dependencies; only including versi…

What's New In Windows Workflow 4.5

Just as I start getting up to speed with WF4.0 MSDN magazine publishes an article detailing what's new in WF4.5. It looks like there's a lot of good stuff coming but the main thing that I noticed was that v4.0 requires full-trust to run. That shouldn't be a problem for the project we're intending to run workflow in, but if it will run in partial trust in the next release that will open up it's usage for many other applications.

Starting Windows Workflow v4.0

Today I've started learning about Windows Workflow v4.0, I'm hoping that it will help out with a current project. The original requirement was for mapping real world business processes to what would normally be complex long running computer tasks. Whilst investigating what it could do I'm beginning to think there could be real value using it for any task that requires process flow logic, even extremely short lived ones. This could be controlling page flow through a web application, or even defining the complex logic that can sometimes end up making MVC controller actions fatter than they really should be.For getting me started a really good starting point has been the MSDN WF4.0 videos under the beginners guide, if you have a PluralSite subscription, Matt Milner presents some really useful stuff too.As well as just learning the basics of Workflow; what really interests me is how it should be architected in a real world LOB application; taking into account the usual &quo…