Monthly Archives: August 2010

Principles of Agile Development

Since taking down the old Clicktricity website, I have had a number of requests to re-publish the agile principles.

Agile Development Core Values

The two most important core values of Agile Development are Communication and Simplicity.

Communication

It is recognised that poor communication in software teams is one of the root causes of failures within projects – whether it be schedule slips, botched requirements, misunderstandings, faulty development assumptions, and the like. Extreme Programming mitigates this by stressing good communication between all project stakeholders – customers, team members, and project managers (or “coaches”) – on a consistent basis. A representative from the customer should be available as much as possible to answer questions and clarify project requirements. Programmers often work simultaneously in pairs, with each programmer reviewing the other’s work.

Simplicity

One of the most common XP slogans is “YAGNI” or ‘You Aren’t Going to Need It’

The principal of YAGNI is that you shouldn’t develop any code that will only be used by a feature that is needed tomorrow. This does not exclude development of flexibility, but it should be kept in check and only functionality that is required now is actually developed.

Agile Development Principles

User Stories

User stories are short, simple descriptions of required functionality that are written by the customer, rather than our interpretation of what the customer wants. The descriptions should only contain sufficient detail to allow development of an accurate estimate for planning purposes, development of unit tests, and are used instead of large unwieldy requirements documents. When we develop and implement the user stories, the developers will work face-to-face with the customer to determine the specific detailed requirements.

Planning

The Planning phase of development is performed in two parts – firstly the “user stories” described above are elicited from the customer. Secondly, the development team estimates development effort for each story. The customer then decides on priorities and agrees what user stories will be implemented in the next release. This defines the project schedule.

Small Releases

The planning phase determines small units of functionality that make good business sense and can be released into the customer’s environment early in the project. This is critical to getting valuable feedback in time to have an impact on the system’s development.

Design Simplicity

The overwhelming aim is to make things as simple as possible. The only code being worked on should be the code that is absolutely necessary to implement the latest user stories, and no more (see YAGNI, as described previously). The drive for simplicity leads to continual refactoring of code, as described below.

Testing

Testing, and in particular writing test specifications from the user stories before coding is another essential component of this technique. Traditional development techniques that follow a “code first, test later” technique are prone to only testing a limited part of the development. In addition it is common that as schedules become tight – thorough testing is often dropped in the interest of expediency, leading to low quality, error prone code. Our technique is to define and develop automated tests before coding ensuring that untested code cannot be released.

Pair Programming

In pair programming, one member of the pair will write code while at the same time another programmer is critiquing the work at hand, and at the same time offering insight as to the next step as well as exposing trivial defects with the code. In tests, pair programming has been shown to be 30% more productive when quality is taken into account, than the combined productivity of two developers working separately.

Refactoring

Once it becomes apparent to the development team that the system design, a module or piece of individual code is becoming too complex, the code is refactored. The refactoring process is one by which the system functionality remains stationary – all tests that pass prior to refactoring should pass after refactoring is completed – but the code base becomes greatly simplified. This may involve eliminating shared code, redesigning model hierarchies and relationships, or simply renaming variables to fit a particular metaphor.

No Overtime

A standard working week with no overtime is strictly adhered to, based on the assertion that development teams are able to produce high-quality product when they are comfortable and not overly-exerted. This principle serves to complement the idea of both pair programming and communication amongst the development team and their customer.

Customer Availability

It is not enough to have only occasional access to a customer and a customer representative should be continuously available to the development team. This ensures that all unanticipated questions or requirements can be immediately resolved and eliminates the need to produce exhaustive and definitive (and probably still incomplete and non-definitive) specifications at the beginning of the project. This also allows the customer to interact with the development and help in the evolution of the product. Maximizing customer availability makes it possible to minimize the time spent on preliminary planning and focus on development, and maximize feedback, thereby increasing the value delivered to the customer.

Coding Standards

The entire development team agrees to maintain a common set of rules concerning the maintenance and creation of new code. These standards greatly simplify communication through common naming conventions and generate shared ownership and responsibility among all developers.

For more information on the principles of Extreme Programming, please see

Clicktricity 5D Methodology

Since taking down the old Clicktricity website, I have had a number of requests to re-publish my 5D development methodology and the agile principals.

Clicktricity 5D

Clicktricity 5D is an agile application development methodology that drives delivery of cost-effective, repeatable, quality solutions in an adaptable framework that suits software development and application implementations for both small and large enterprises.
 
The 5D methodology allows us to consistently provide the following:
  • Accurately determine business and commercial requirements
  • Design solutions that meet client’s short and long terms needs
  • Develop quality applications, on-time, on-budget
  • Implement solutions with minimal impact to ongoing business operations
  • Provide comprehensive handover and ongoing support of delivered solutions
The 5D methodology is an iterative process consisting of the following standard phases, which may be repeated as necessary for each phase and sub-phase of a project/

1. Discover

Analysts and solution architects work closely with the client to understand and accurately document the business, commercial and operational requirements. They map out the project timeline, risks, impact and deliverables, and divide the project up into short, medium and long term achievable and measurable milestones in order that progress can be accurately tracked, monitored and managed.

2. Design

The detailed design stage builds upon the initial discovery analysis and describes in detail exactly what is required, how it will be achieved and the process that will be used to produce the final result.

3. Develop

Using an iterative cyclical process, we develop, test and QA the solution according to required quality and development standards. In addition, we keep the customer involved in every step of the development process including functional prototypes and pre-release candidates.

4. Deliver

Deliver the completed solution and install it in the customer’s environment. Then work with the customer to complete acceptance tests and verification of functionality.

5. Deploy

Work closely with the client’s resources to deploy the application, complete the handover, documentation and provide any user training that is required. Complete a comprehensive post-project review to ensure that we have met every requirement.

Populating common view model attributes

In many ASP.Net MVC based applications, we often find ourselves needing to include the same information in every page.  Such information typically includes details of the current user, maybe environmental values and running totals like the number of items in a shopping basket.

In order to ensure these values are always available in views, base your view models on a common base class, and populate these base values using an action filter.

public class ViewModelBase
{
   public string UserName { get; set; }
   public List<UserFavorite> UserFavorites { get; set; }
   public ShoppingBasket ShoppingBasket { get; set; }
}

Then, create an action filter to populate this, if it has not already been populated by the action method on which it has been applied.

// Populates View Model base properties, if they are not already populated by the controller
class ViewModelAttribute : ActionFilterAttribute
{
   public override void OnActionExecuted(ActionExecutedContext filterContext)
   {
   ViewModelBase viewModel;

   if (filterContext.Controller.ViewData.Model == null)
   {
      viewModel = new ViewModelBase();
      filterContext.Controller.ViewData.Model = viewModel;
   }
   else
   {
      viewModel = filterContext.Controller.ViewData.Model as ViewModelBase;
   }

   if (viewModel != null)
   {
      viewModel.UserName = lookupUserName();
      viewModel.UserFavorites = GetUserFavorites();
      viewModel.ShoppingBasket = GetShoppingBasket();
   }

   base.OnActionExecuted(filterContext);
   }
}

The code first checks for a null model and assigns a base view model if none exists.  It then checks that if a model does already exist, that it is of type ViewModelBase.  If so, the appropriate values are initialized.

Then, on any action method that required this – or (in my case) at the controller level of a base controller class, add the attribute:

[ViewModel]
public abstract class ControllerBase : Controller
{
 /// Controller base

}

Rendering views to strings

Rendering a view or a partial to a string is a common problem, especially when you want to re-use your code and markup in a PDF or Email.  There are a number of semi-successful methods for achieving this across the internet.  The techniques outlined below are built on the excellent post from Kevin Craft at http://craftycodeblog.com/2010/05/15/asp-net-mvc-render-partial-view-to-string/ this has the advantage of being simple, straight forward and fully support embedded Html helpers.

Render Partial To String & Render Form To String

Define the following within a Controller base class:

public class BaseController : Controller
{
   protected string RenderPartialToString(string viewName, object model)
   {
      if (string.IsNullOrEmpty(viewName))
         viewName = ControllerContext.RouteData.GetRequiredString("action");

      ViewData.Model = model;
      using (StringWriter sw = new StringWriter())
      {
         ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);
         validateViewResult(viewResult, viewName);
         ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
         viewResult.View.Render(viewContext, sw);
         return sw.GetStringBuilder().ToString();
      }
   }

   protected string RenderViewToString(string viewName, object model, string masterName)
   {
      if (string.IsNullOrEmpty(viewName))
      viewName = ControllerContext.RouteData.GetRequiredString("action");
      ViewData.Model = model;
      using (StringWriter sw = new StringWriter())
      {
         ViewEngineResult viewResult = ViewEngines.Engines.FindView(ControllerContext, viewName, masterName);
         validateViewResult(viewResult, viewName);
         ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw);
         viewResult.View.Render(viewContext, sw);
         return sw.GetStringBuilder().ToString();
      }
   }

   private static void validateViewResult(ViewEngineResult viewResult, string viewName)
   {
      if (viewResult.View != null)
      return;
      // wasn't found - construct error message
      StringBuilder locationsText = new StringBuilder();
      foreach (string location in viewResult.SearchedLocations)
      {
         locationsText.AppendLine();
         locationsText.Append(location);
      }
      throw new InvalidOperationException(String.Format("View {0} not found. Locations Searched: {1}", viewName, locationsText));
   }
}

Then, within your controller action methods you can use something similar to this:

string partial = RenderPartialToString("TestPartial", "This is my test partial");
string viewString = this. RenderViewToString("", null, "");