Broloco

Introduction

Most software development teams are now Agile ... or at least they're calling themselves Agile. In addition, I see many claiming to practice all the right techniques. I often find, however, that when you look behind the scenes they are making fundamental mistakes in their implementation.

Continuous Integration is arguably the most important practice you need to be Agile. If you're not constantly integrating new functionality into the existing system, and verifying that it doesn't break the existing functionality, then you are going to struggle to deliver incrementally.

Build on the Developer's Machine

A not uncommon mistake is to put the automated build on a server ... and only on the server. I've seen teams spend time getting the 'build server' set up in such a way that it's the only machine in the department that can actually run the build (and the tests).

This sometimes comes from the misunderstanding that the build tool is not the scheduler that runs on the server (e.g., CCNet). It's usually a command-line driven tool like NAnt or MSBuild. (This kind of misunderstanding can lead to a discussion like the following: link.)

Incidentally, I'm a huge fan of CCNet, and have used it almost everywhere I've worked. However, as James Shore has pointed out before, people can have a tendency to be distracted from the actual practice of Continuous Integration in favour of getting a build server working.

Integrate with ALL Code

So you've got the build going, and people are running the build locally before checking in. So now you're practising Continuous Integration, right? Well ... maybe.

Despite TDD not being a new technique, I think it is (unfortunately) still far from mainstream. A team might try to introduce (or increase the amount of) automated testing but, as James Shore points out, it is fundamental that the entire team agrees (see step 5 here) to practice Continuous Integration. Not only important that they all buy into the practice, but that they all understand the practice and what it entails.

When the developers adds a new feature to the existing code, they typically have to modify an existing implementation. They will try hard (sometimes very hard) not to break the existing implementation. Unfortunately, some developers might not extend that care to the tests.

I've seen developers treat tests as 'special' code that is immune to these rules. It is sometimes seen as acceptable to ignore tests (using the [Ignore] attribute), remove the [Test] attribute completely so they don't even get reported as ignored, or worst of all comment them out or delete them! The effect of this has been described as Test Cancer.

The excuse is often that it was 'pragmatic' ... where 'pragmatic' is used as a euphemism to being reckless or irresponsible. If you're practising Continuous Integration properly, then you should be integrating with all the existing code, and that includes the tests.

The Implementation as a Second-Class Citizen

Accepting that tests should be treated with the same priority as the implementation isn't far enough in my opinion. For those practising TDD the tests are significantly more important than the implementation.

Each test that gets added to the solution acts as an invariant, and might change little during the development of the product. It is the implementation that changes constantly to accommodate each new requirement as the project progresses. It is the implementation where pragmatic approaches like faking and hard-coding are acceptable until there is a test that demonstrates the need for it to evolve past the simplest solution.

You can see this effect in action very clearly while watching one of Uncle Bob's Katas (e.g., the Prime Numbers Kata); the tests, once written, are static, but the implementation is open to constant redesign/rework. (Note, I'm avoiding the much abused term Refactor here deliberately).

Once you've embraced the tests and are continually integrating with them, the implementation becomes a secondary concern that is an output designed (and redesigned) to satisfy the all tests. The implementation becomes the second-class citizen that is open to faking and hard-coding, while the battery of tests mean "you just don't have to worry where you walk".

Summary

In order to say you are practising Continuous Integration correctly, the following should be true:

  • The whole teams is collectively agreeing to the practice;
  • The automated build (including tests) must be runnable on a developer's machine;
  • The tests are treated with at least the same priority as the implementing code;
  • There is nothing more important than a broken build!

Do not think of tests as second-class citizens in the code. Instead strive towards the tests being the input, and the implementation becoming an output that passes the tests.

Finally, I don't think I've said anything new here; just reiterated many people's well worn points that have stood the test of time. I firmly believe that ignoring these points can cause a sharp decline in project quality, and that teams should bear them in mind before claiming to be Agile, or claiming they are practising Continuous Integration.

Submit this story to DotNetKicks Shout it

As I explained previously I tend to complete an Iteration 0 prior to the rest of the development team starting work on a project as I feel it helps ensure that the development team can be as productive as possible when they start.  Normally I spend this time coding alone, but consulting with others as required, putting the structure of the system in place.  I make decisions about the main structural patterns we're going to use (e.g.,  Domain Model, Service Layer etc.) and the technologies (e.g., NUnit, NHibernate, Spring.NET etc) but I try to defer as many as I reasonably can.  If I don't spend this time I've found that Iteration 1 is spent arguing about the best way to do just about everything and frankly when you're working on fixed price contract you just can't afford that.

Once Iteration 0 is complete and the rest of the development team start they concentrate on cranking out functionality as quickly as they can.  They don't really need to know about the dependency injection framework, the fancy AOP aspects intercepted to provided comprehensive logging to all the services exposed.  The project naturally gathers pace and for most of the developers the plumbing code is a bit like magic: it just works!  They don't know how and, to be honest, they don't need to.  It's at this point when the warning signs appear.  If you're the Technical Lead and nobody on your development team is starting to ask those awkward questions that make you re-evaluate your view on things like "why is the logging like this?", "why aren't we using Fluent NHibernate", start to worry.  If nobody on the development team other than you is taking the time to understand what's going on under the hood and questioning your decisions, rest assured that if you step off that project monsters will be eating your bridges in no time at all.

Now, on one of the systems I've built when I stepped off and went back later to make a bug fix, there was no sign of monsters.  So the question is: what was different? The answer is that on the project one of the less experienced developers on the development team started asking awkward questions and I started answering them.  Some of the questions were straightforward to answer, but some of the questions made me really question the decisions I'd made.  The less experienced developed started to understand not only how things were put together but why.  They started to learn, fast!  When the time came for me to step off the project they were then capable to assume the role of Technical Lead and the "Sim City" effect didn't happen.  Sure when I returned things had changed but there was no monsters in site.

Submit this story to DotNetKicks Shout it

I tend to fulfil the technical lead role on the projects I work on.  This role means that I’m overall technically responsible for the system.  Put simply: the buck stops with me!

As such, at the start of each new project I tend to spend a week or so working long hours getting the “framework” of the application in place and, attempting to provide the simplest end-to-end example of how the system will be structured that I can.  I also used to write a document that explained the shape of the system too, but I’ve found, through costly experience, that nothing matters more than an end-to-end example in code.

Despite protestations from the “truly agile” I believe this time is well spent getting the various architectural elements of the system , the levels of testing, and the tools we are going to use in place and thankfully I’m not alone in this.  Over the course of the project these decisions will bend, some may be completely reversed, but largely they’ll stay with the project until it’s dying day.  Once the framework is in place, more junior developers can be productive very quickly and concentrate primarily on business functionality and not technical “plumbing”.

Typically, I work on the project through to completion and work as a senior programmer on the project.  Unfortunately sometimes I’m forced to “step off” from a project before it’s completion.  It is when this happens that I tend to see something I’ve termed lovingly the “Sim City” effect.

For those who remember playing Sim City this scenario may sound familiar…

In the older versions of Sim City (I’ve no idea about the newer versions as I moved on to Championship Manager when I hit 12!), you could spend the first couple of hours of the game getting into loads of debt building you’re beautiful city utopia.  All shiny and new you marvelled at how good your Police and Fire Service coverage was and you watched the taxes roll in from happy citizens.  It was around this time that typically your mother shouted you for dinner and you left the city to it's own devices.  An hour or so would go by and eventually you head back to your bedroom and your beautiful utopia.  But what’s this?  Monsters eating your previously beautifully crafted bridges, mass civil unrest and power cuts all over the city.  Despair typically follows… followed by a shutdown!

So the same feeling of despair I got when I returned to my once utopian city can also occur when I return to a project I've started but never got to finish.  My once beautifully crafted tests are now broken or worse ignored.  CruiseControl is shot to bits, and where previously RhinoMocks nicely mocked out underlying system layers to facilitate true unit tests these have been superseded with hand cranked stub classes that have roughly as many lines of code as there are stars in the universe! 

Martin Fowler talked about Test Cancer and, despite some rather emotive language, I think that is just one of the “monsters eating your bridges” that you can see.  Architectural and methodological deviation in general tend to be common place.  That’s not to say it happens all the time and it’s worth remembering too that utopia is in the eye of the beholder but in my experience, the “Sim City” effect is all too common.

Submit this story to DotNetKicks Shout it

Introduction

If you have a Domain Model, you're going to have code that validates rules and checks for inconsistencies. Methods in the Domain Model are going to have to indicate failure in some way (often corresponding to an exception scenario in a use case).

My personal preference is always to start with the simplest way of handling business logic errors: throw an exception.

Avoid Return Codes

We know that the wrong way to indicate a problem is by using an error return-code from each function. The call-stack can be quite deep, and you cannot (and should not) rely on the callee of each function to check each return value.

We also know that failing fast is (perhaps unintuitively) the way to write more stable applications.

Exceptions are a language mechanism that is perfect for indicating that something has failed. The semantics allow you to 'get the hell out of Dodge' without having to worry about handling the failure, or how deep in the call stack you are. If the exception is not handled correctly, it will expose the problem in an obvious way.

Additionally, throwing an exception means that you don't have to worry about the code that would have been executed next. This can be of advantage where:

  • The subsequent code would otherwise have failed (e.g., if the validation found that a string was not unique and inserting it into a database would cause a unique-key violation);
  • The subsequent code used a non-transactional resource (e.g., a synchronous external web service, or the file system.)

Catching Exceptions in the Presentation

When you're handling exceptions in the Presentation layer you have an opportunity to concisely handle the specific scenarios you know about while elegantly ignoring any others:

public void CreateButton_OnClick()
{
    try
    {
        library.CreateBook( View.BookTitle,
                            View.BookAuthor,
                            View.BookDescription);
    }
    catch (BookTitleNotUniqueException)
    {
        View.ShowMessage("The supplied book title is already in use");
    }
}
        

The above try-catch construct provides a way to indicate that there is a programmed response when the supplied name is not unique. More importantly, it indicates that any other error should automatically be propagated up the call chain.

Service Layer

Many applications still separate the presentation from the domain with a (remote) Service Layer. However, most remoting technologies (e.g., WCF Web Services) don't play well with exceptions.

Typically the Service Layer will catch the exception, roll-back any transaction, and use a custom DTO or framework-provided mechanism to pass the details of the exception the to client. (WCF supplies the FaultContract class for this)

The DTO should be turned back into an exception on the client-side (using AOP/interception) so that it will still be propagated up the call chain if it is not handled. When using WCF it is advisable to convert the FaultException object back into a regular exception to prevent coupling your presentation layer to WCF.

Where you have no Service Layer, you'll probably need to call a method (probably in the constructor of your custom exception class) to indicate to any transaction handler that the transaction should be rolled back.

Multiple Failures

A common scenario where failing fast is not immediately suitable is where the client wants multiple validation errors handled in a single call.

In these cases I try to wrap the multiple checks into a fluent interface that throws a single exception that contains a collection of validation errors. The code might look something like:

new ValidationBuilder()
    .Add(ValidateAddressLine1())
    .Add(ValidateAddressLine2())
    .Add(ValidateAddressLine3())
    .Add(ValidatePostcode())
    .ThrowOnError();
        

While this is a common scenario to find in Internet applications, (e.g., when filling out your car insurance quote online), it is rarely required for every screen of an average internal LOB application.

I personally try to avoid this until the client asks for it. The logic required to continue the validation code typically becomes harder to write when you can't assume that preceding validation was successful.

Common Arguments

There seems to be conflicting advice on using exceptions, with common advice being to avoid them for anything other than runtime errors in the infrastructure (e.g., disk full, connection broken, etc.) I am not aware of a technical reason for not allowing exceptions to be used for business logic errors.

Others have sophisticated solutions for passing notifications out from the domain that avoid the use of exceptions. I try to avoid resorting to more complicated solutions until they are required - exceptions are a simple mechanism that are easily understood by programmers.

Less interesting arguments, however, usually revolve around performance. Any performance loss from throwing an exception is usually insignificant by comparison to the length of time taken for the business transaction itself.

Summary

Exceptions are the perfect mechanism for reporting inconsistencies in domain logic. I believe judicious use of them will make your applications more stable, and make your code neater and easier to maintain.

Be wary of anyone telling you that this is not what exceptions are for ... this is exactly what they are perfect for!

Submit this story to DotNetKicks Shout it

After reading Ayende’s recent blog post it got me thinking about a situation I regularly find myself in when building systems.  Whilst Ayende’s post mentions that he’s not really interested in whether a child is responsible for creating itself or whether a parent is responsible for creating a child, I personally always favour the later. 

However, whilst some objects within a domain model have an obvious parent that is also within the domain model some simply don’t.  In these situations the question about who is the responsible party is slightly more confusing as whilst (as a child object) I know I’m not the responsible party for something I don’t really have anyone who is. 

In these situations I create a notional “parent” for these orphans.  I call this object the “System” or “Mother” object as the only reason it exists is to act as parent for objects who have no notional parent.

So who is the responsible party when nobody loves me?  Simple, someone always loves you! :-)

Submit this story to DotNetKicks Shout it

I've found that the best way to get to understand a particular technology is play around with it. As such, when I started working on a WCF project for one of my customers I created a simple test harness that let me play about with WCF Service Contracts and WCF Data Contracts quickly and easily.  Anyway, I've made my WCF test harness available here:

http://code.google.com/p/koln/

The test harness uses RhinoMocks to mock out my WCF Services and NUnit to enable a simple set of automated unit tests.

Submit this story to DotNetKicks Shout it

(or Using NHibernate and WCF)

Introduction

If you have a Domain Model, and a rich-client (e.g, WinForms/WPF), you might want to expose your application's functionality across a Service Layer/ Remote Facade. Your Service Layer will need to return objects containing domain information, and I prefer to re-use my Domain Model classes directly, rather than invent unnecessary DTO objects (DRY).

Typically your Domain Model might be entities mapped to a relational database using NHibernate (or some other ORM), and a Service Layer exposed using WCF (or some other remoting technology).

This should be simple, however there are a few issues you might run into.

Lazy Load

Most good ORM solutions will use Lazy Load to allow the domain objects to access each other using their associations while silently taking care of the data-access concern.

When you come to serialise an object that came from a connected Domain Model you now have a problem. With Lazy Load it's like pulling a loose thread that could potentially load up the entire object model into memory. You need a way to indicate the 'section' of the object graph that you want.

Lazy Load is also often implemented using interception, which in turn usually means that the object might actually be a generated proxy. Some remoting technologies do not play well with auto-generated classes; you might need to transform them back to their 'real' class to send them across the wire.

(WCF can generate a System.ServiceModel.CommunicationException: ... Add any types not known statically to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding them to the list of known types passed to DataContractSerializer)

In addition, the serialisation of the objects often occurs after the service call is complete. If the database connection is already closed then you may be unable to Lazy Load more of the domain.

(NHibernate can generate a NHibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed)

Domain Object Graph Depth

Some ORM solutions allow you to 'disconnect' a portion of the object graph to prevent Lazy Load issues, but then you have to handle two further issues:

1. Loaded Graph is Too Deep ...

During a single service call the domain objects might load a deep graph to solve a given problem, and then return a single object as its result. In this case the loaded object graph might be much larger than you want to send across the wire. (Either for performance reasons, or security reasons perhaps.)

2. Loaded Graph is Too Shallow ...

Other times the graph will only be partially loaded, and you want to return a result from a service call that loads deeper information. For example, a call GetPersonDetail() might need the Person object, and it's parents, children, addresses, ... or specifically exclude some personal details. In addition, you need to be careful not to fall into the select N+1 problem while fetching all the objects you want.

In both of these cases you again need to indicate the portion of the object graph that needs to be sent across the wire.

Cyclic Object Graphs

Most connected Domain Models are full of cyclic references, with bi-direction associations between objects being common. A typical object-graph for these classes:

public class Person
{
    // 1:m association between Person and Child
    public IList<Child> Children;
    ...

public class Child
{
    // m:1 association (back pointer)
    public Person Parent;
    ...
        

... might look like this in memory:

However, if you're going to try exposing your services using SOAP you're going to find out that cyclic graphs like this are not allowed. (I can only assume the guys that defined SOAP (WS-I) were asleep the day they decided that no-one would need to send cyclic graphs across the wire.)

To send this across the wire you might need to transform the above graph into something like this:

Solving Using a Graph Utility Class

My preferred option for sorting these problems is to use a utility class that allows you to quickly specify a graph of objects to 'copy'.

With a sprinkling of Lambda Expressions and extension methods you can have code that looks like something like this:

// Copies a person, its children (with its parent),
// and the grandchildren.
Person personCopyToReturnAcrossWcf =
    myRootPersonObject
        .Graph()
        .Add(p => p.Children, new Graph<Child>()
            .Add(c => c.Parent))
            .Add(c => c.Granchildren))
        .Copy();
        

The source for the utility class can be found here: link

Finally

Some people dislike the idea of sending the 'real' domain objects across the wire. Instead they create DTO objects for everything that has to be passed back from a service.

My personal preference is to only create DTO classes when they are needed, hopefully saving time on creating both the DTO objects and the code to map my domain properties to them. Reporting is an example where this usually breaks down and I find myself creating DTO classes to send information to a client.

Utimately, whether you use graphing, or use DTOs, you still have to be aware of all of the above issues when using a Domain Model and a Service Layer/Remote Facade.

Submit this story to DotNetKicks Shout it

I'm a big fan of NHibernate, and also of its Query Object the ICriteria API. I don't much care for 'magic strings' in my code though.

LINQ provides a way to strongly type your queries, but there are still times when you want an opaque query language with an object-oriented interface.

With .Net 3.5 came Lambda Expressions, which allow you to strongly type the individual expressions in a query. I started writing some extension methods to allow me to use lambda expressions with ICriteria, so code like:

mySession
    .CreateCriteria(typeof(Person))
        .Add(Expression.Eq("Name", "smith"))
        .List<Person>();
        

... turns into code like:

mySession
    .CreateCriteria(typeof(Person))
        .Add<Person>(p => p.Name == "smith")
        .List<Person>();
        

There turned out to be quite a few extension methods to write to cover all the different combinations of ICriteria that can be written (including DetachedCriteria, aliases, subqueries, ...) I've packaged it into a project on Google Code for anyone who wants to use it:

Submit this story to DotNetKicks Shout it

An Alternative to CodeSmith

I'm a big fan of code-generation for automating boiler-plate code. I used to use CodeSmith for this, but the freeware version is no longer maintained. T4 is my new favourite tool for code generation, and there's a wealth of information available on using it on Oleg Sych's site.

Passing Command-Line Parameters to TextTransform

The tools come with a command-line host for T4 (TextTransform.exe), but there's no obvious way to pass parameters to the templates.

You can pass parameters using the command-line option -a:

TextTransform.exe
    -a mappingFile!c:\myPath\MyClass.hbm.xml
    -out c:\myGeneratedFiles\MyClass_Generated.cs
    c:\myTemplates\GenerateNHibernateProperties.tt
        

In order to retrieve the parameter from inside the template, you can use a little reflection:

private string GetCommandLineProperty(string propertyName)
{
    PropertyInfo parametersProperty =
        Host
            .GetType()
            .GetProperty("Parameters",
                BindingFlags.NonPublic | BindingFlags.Instance);

    StringCollection parameters =
        (StringCollection)parametersProperty
            .GetValue(Host, null);

    foreach (string parameter in parameters)
    {
        string[] values = parameter.Split('!');
        int length = values.Length;
        if (values[length - 2] == propertyName)
            return values[length - 1];
    }
    return null;
}
        

Replacing NHibernate Magic Strings

Now I can loop through my .hbm.xml files in my build, generating the 'magic strings' for the properties of each class (example template and project is linked below).

This turns code like:

IList<Media> mediaWithNameAndType =
 DomainRegistry.Repository
  .CreateQuery<Media>()
  .Add(Expression.Eq("OwningLibrary", this))
  .Add(Expression.Eq("Type", media.Type))
  .Add(Expression.Eq("Name", media.Name))
  .List<Media>();
        

Into code like:

IList<Media> mediaWithNameAndType =
 DomainRegistry.Repository
  .CreateQuery<Media>()
  .Add(Expression.Eq(Media.Properties.OwningLibrary, this))
  .Add(Expression.Eq(Media.Properties.Type, media.Type))
  .Add(Expression.Eq(Media.Properties.Name, media.Name))
  .List<Media>();
        

Some links:

Submit this story to DotNetKicks Shout it

Introduction

In a previous post I demonstrated testing a Compact Framework application using Passive View. I also mentioned that I would use the same technique to test the presentation layer on other platforms. So to put that to the test I migrated that simple application to Silverlight.

Testing Platform

There are many more testing options for Silverlight than there are for the Compact Framework. If you're using the IDE, you might consider reading this for some of your options.

I chose to test my POCO controller classes inside the regular .Net framework using NUnit.

Instead of retargeting, I cross-compiled the controller class to the 'real' .Net framework. The view controls in Silverlight are a subset of the complete WPF controls, so they can be substituted in the test environment to simulate the runtime controls.

The only slight hindrance I came across was that when you attempt to use the WPF controls in NUnit you get the exception "InvalidOperationException : The calling thread must be STA". The controls insist on running on an STA thread, which requires a .config file for the test assembly containing the following:

<NUnit>
    <TestRunner>
        <add key="ApartmentState" value="STA" />
    </TestRunner>
</NUnit>
        

Passive View

As previously, the view is completely dumb. It contains no logic, just the controls that will be manipulated by the controller. The XAML is kept simple with mostly positioning logic.

<StackPanel x:Name="LayoutRoot"
    Background="White">

<TextBlock>
    Demonstration of Passive View to test
        Silverlight client
</TextBlock>

<Button x:Name="ShowMessage"
    Content="Show Message"
    Width="150"  Margin="20"/>
...
        

I exposed the controls as public fields on the View class. These were populated in the 'Loaded' event (note, this only fires in the Silverlight runtime - not the tests), then the controller was wired up:

public class MainView : UserControl
{

  public Button ShowMessage;
  public TextBlock Message;
  ...

  public MainView()
  {
    Loaded +=
      new RoutedEventHandler(UserControl_Loaded);
  }

  private void UserControl_Loaded(object sender,
      RoutedEventArgs e)
  {
    ShowMessage = (Button)FindName("ShowMessage");
    Message = (TextBlock)FindName("Message");
    ...
    new MainController(this);
    ...
        

During the tests a testable view class simply populates the fields with 'empty' controls allowing the controller logic to be tested, without requiring a full presentation runtime.

public class TestableView : MainView
{
  public TestableView()
  {
    ShowMessage = new Button();
    Message = new TextBlock();
    ...
    new MainController(this);
    ...
        

Migration from Windows Forms

The only remaining task was to migrate the namespaces to WPF from Windows Forms. Mostly this was just a search/replace exercise (with the compiler telling me everywhere something had changed):

  • Namespace moved to System.Windows;
  • Enabled property is now IsEnabled property;
  • MessageBox.Show has slightly fewer options;
  • Setting colours now uses a Brush class;
  • etc., ...

With just a little more work, you could wrap each control in a common interface (e.g., IButton, IComboBox), then the same controller could be used to run a view on multiple platforms (Silverlight/WPF/Windows Forms). You might even be able to use the controller to run a web application using a framework like Visual WebGui (which makes coding a web application magically like coding a Windows Forms application).

For a larger application I would definitely do this extra work - it is bound to pay itself back at some point, not least of all because you could have stubbed control implementations in the tests instead of the 'real' ones.

Summary

The modifications to move the demo from Windows Forms to Silverlight were a rewriting of the View (inevitable), and some minor syntax changes in the controller.

On a larger application the ability to keep 90% of your code (and the tests!) when migrating to another platform is invaluable, and Passive View is the best way I've seen of writing (and testing) the presentation layer.


Silverlight Passive View Demo
download, unzip, run CommandPrompt.bat, and type 'NAnt'

View Silverlight Passive View Demo Online

Submit this story to DotNetKicks Shout it

Following Richard's "HTML is crap" post this got me thinking about the real underlying message of his post. Yes technology has moved on a lot in recent years to the point where old reasons for choosing those [HTML applications] types of application have largely gone. However this isn't the first or the last time software people will have this frustration and here's why: too many business people come with software solutions and not business problems! I've no idea why this has happened other than some mistaken idea that software is easy and business is hard. In my experience when customers bring me software solutions rather than business problems the final software solutions I'm able to deliver to them are invariably poorer than they should be. So the next question is how can we stop people bringing us their half-baked solutions...

Submit this story to DotNetKicks Shout it

OK, so it's not crap. It's great for web sites, disseminating and formatting information, and linking content across the entire world. In fact, it's pretty amazing. But ... it is crap for writing applications.

Over the years we have jumped through all sort of hoops to get round the (extreme) limitations of HTML and browser technology. We have invented ways of maintaining user state by keeping cookies on browsers, by adding cryptic information to URLs, by posting hidden values in forms, and by restoring large state objects on the server to overcome some of these problems.

We have invented increasingly complicated frameworks to allow us to split presentation logic over two physical tiers with a (typically) compiled language running on the server while Javascript manipulates widgets on the client, and then found more and more ingenious ways of making this seem slick to the user. We have made code more complicated by the fact that these two separate tiers have to communicate in some fashion, and we convince ourselves that the solution is elegant.

As soon as we have to target more than one type of browser (or even different versions of the same browser) it is not going to look the same on what is essentially different platforms. (Not to mention the difficulties of actually writing and debugging for two versions of IE on the same machine.) You would have to be nuts to choose a platform where the output will be unpredictable, right?!

A common argument with the customer might go something like this:

Programmer: You have high expectations of usability. It is best to use a rich client.
Customer: It needs to be a web (HTML) application.
Programmer: Um ... why?
Customer: Because that's what we want.
Programmer: You do realise it will take twice as long to write, and be less usable?
Customer: It needs to be a web (HTML) application.
Three months later the programmer is blamed for the product not being amazingly slick, being slightly behind the time-scales, and the customer is insisting that they need their spelling mistakes underlined 'just like MS Word'!

Another common reason for a customer to insist on a web application is for ease of deployment, but it is not hard to push rich applications to the desktop using technologies like ClickOnce these days either.

The only people who most often have a genuine need to target such a low common denominator are those writing applications that target the Internet (e.g., Amazon, eBay, etc.) But even then it is clear that for years the best looking stuff on the web has Flash content.

In summary:

Choose WPF;
Choose Windows Forms;
Choose Silverlight;
Choose Flash;
Just don't choose HTML.

Choosing to write an HTML application, especially when you are going to deploy in a company intranet, is nothing short of insanity these days ... it's long past the time for developers to make customers realise this.

Submit this story to DotNetKicks Shout it

The Challenge

You have a Compact Framework application to write. You've chosen to make it a rich client (Windows Forms), and you want a suite of automated tests covering the code.

Passive View

I investigated the options for testing directly on the Compact Framework itself, but this turns out to be tricky and ties you to running inside the emulator (a virtual machine).

However the Compact Framework uses a .Net feature called retargeting. This allows your Compact Framework code to be run in the full .Net environment as long as it doesn't reference any classes that are unique to the Compact Framework (e.g., the SIP).

If you use Passive View, you can take your controller class and test it in the regular .Net Framework using NUnit leaving only a tiny bit of code in the View that is specific to the Compact Framework.

Creating the View

In the example code below I created a simple GUI that would show or hide a message, allow the user to change the colour of the message from a drop-down, and would prompt the user for confirmation before hiding the message. This provides a simple enough example to cover in a blog, while being complex enough to demonstrate several useful techniques for testing using Passive View.

The view can be created directly in Visual Studio (with the Window Mobile 6 SDK installed). The designer gives you an excellent rendition of a PDA client making it easy to design a user interface (notwithstanding that WPF would have been nicer - but hasn't been implemented on the Compact Framework yet).

To create the view:

  • Create a Form;
  • Create the controls;
  • Name the controls, and mark them with the modifier 'Public';
  • Wire up a controller when the View is instantiated.

To wire up a controller, create a controller class (which is going to hold all the application's presentation logic), and construct it when the View is instantiated.

internal class MainController
{

    private MainView _view;

    public MainController(MainView view)
    {
        _view = view;
        ...
        
public partial class MainView : Form
{

    public MainView()
    {
        InitializeComponent();
        new MainController(this);
        ...
        

And that's it. No other logic should exist in the View.

Handling User Input

Most of the user input can be handled directly on the View in the tests. To simulate someone typing into a text-box, simply set the Text property. To simulate someone making a selection from a drop-down, set the SelectedIndex property.

Simulating a button 'click' requires a tiny bit of reflection to invoke the protected method:

private void Click(Button button)
{
    if (!button.Enabled)
        Assert.Fail("Attempt to click button '"
            + button.Text
            + "' while it is not enabled");

    MethodInfo onClick = button.GetType()
        .GetMethod("OnClick",
                    BindingFlags.NonPublic
                    | BindingFlags.Instance);
    onClick.Invoke(button, new object[] { null });
}
        

You end up with a fairly readable test:

[Test]
public void Test_WhenShowMessageIsClicked_Then_…
    MessageIsDisplayed_And_ColourSelectionIsPopulated()
{
    MainView view = new TestableView();

    Click(view.ShowMessage);

    Assert.AreEqual(false,
                    view.ShowMessage.Enabled);
    ...
        

Handling the Visible Property

You can set most properties directly on the real framework classes. However, some properties don't always behave correctly outside of the Windows Forms runtime. The Visible property is one such case.

You could mock/stub the Visible property on the controls, however typically these might get called many times in a single test; mocking could make your tests very brittle. Alternatively you could have an adapter/proxy for each of the controls that let you simulate events/properties.

I find it easier to have a fake implementation I can use just inside the tests. In this example I wrapped all calls to the Visible property with a (virtual) method:

public partial class MainView : Form
{
    ...
    public virtual void SetVisible(
                            Control control,
                            bool    isVisible)
    {
        control.Visible = isVisible;
    }

    public virtual bool IsVisible(Control control)
    {
        return control.Visible;
    }
    ...
        

This was replaced with a fake implementation in the tests:

public class TestableView : MainView
{
    ...
    private Dictionary<Control, bool>
        _controlVisibility
            = new Dictionary<Control, bool>();

    public override void SetVisible(
                            Control control,
                            bool    isVisible)
    {
        _controlVisibility[control] = isVisible;
    }

    public override bool IsVisible(Control control)
    {
        if (!_controlVisibility.ContainsKey(control))
            Assert.Fail("Control '" + control.Name
                + "' visibility has not been set by…
                SetVisible()");

        return _controlVisibility[control];
    }
    ...
        

Handling User Interaction

Another thing that needs to be tested is user interaction (e.g., clicking yes/no on a message box). While you could use a test double/stub for this, it does tend get a little tedious (you typically end up with a different stub method for every test).

It is better to Mock the user input by (in this case) creating a proxy to the message box class instead of going to the (hard to test) static methods directly:

public class DialogHandler
{

    public virtual DialogResult ShowMessageBox(
        string                  text,
        string                  caption,
        MessageBoxButtons       buttons,
        MessageBoxIcon          icon,
        MessageBoxDefaultButton defaultButton)
        ...
        

In this example I've used the excellent Rhino Mocks to mock the DialogHandler implementation. So you can set expectations, and their responses, directly in the tests:

[Test]
public void Test_WhenHideMessageIsClicked_…
    AndUserConfirms_Then_MessageIsHidden()
{
    MockRepository mocks = new MockRepository();
    DialogHandler dialogHandler =
        mocks.StrictMock<DialogHandler>();
    MainView view = new TestableView(dialogHandler);

    Expect
        .Call(dialogHandler
            .ShowMessageBox(
                "Are you sure?",
                "Check",
                MessageBoxButtons.YesNo,
                MessageBoxIcon.Question,
                MessageBoxDefaultButton.Button1))
        .Return(DialogResult.Yes);

    mocks.ReplayAll();
    Click(view.ShowMessage);
    Click(view.HideMessage);
    mocks.VerifyAll();
    ...
        

Summary

Now you have the highest possible test-coverage on your presentation layer, without resorting to (heavyweight) full integration/acceptance tests.

The example code (link below) demonstrates each of the above sections using:

  • NAnt and NUnit - to automate the build and tests;
  • Retargeting - to allow the Compact Framework classes to be tested inside the regular .Net Framework;
  • Passive View - to allow testing of as much of the application as possible while not requiring the Windows Forms runtime;
  • Test Double - (specifically a fake ) to allow testing of properties that normally only work in the Windows Forms runtime;
  • Mocks - using the excellent Rhino Mocks to test user interaction in the tests.

Worth noting is that there is nothing here that is special to the Compact Framework. I would use exactly the same technique to test any presentation layer (e.g., WPF/Silverlight). The Compact Framework is merely a useful demonstration of where the real runtime is not easy to use, and these design patterns and testing techniques shine.


Passive View Demo
download, unzip, run CommandPrompt.bat, and type 'NAnt'

Submit this story to DotNetKicks Shout it

In my continuing adventures with legacy code I've inherited a code base that initially had over 500 compiler warnings. Now many of these warnings were pretty straightforward to fix but some of them are proving a little more interesting. My current personal favourite is CS0252.

I've got around half a dozen places where it's really unclear as to exactly what the original programmer was intending to do. Was he/she really meaning to do a reference comparison? Unlikely. So now I've got an interesting predicament. Do I change the code to remove the warning or do I leave the code as is and accept that as it's a legacy system the code must work fine. Safety (and sadly professionalism) must win and in these situations I must leave the code as is until I get round to covering the relevant code with tests. However it's like a real stone in my shoe and I've got to ask: wouldn't it have been so much nicer if the original programmer simply looked at the warning and thought, "I don't think that's quite right...."?

So the moral of the story is please pay attention to your compiler warnings. They'll help you identify potential bugs in your code and they might even help write code that's easier to understand and consequently more maintainable.

Submit this story to DotNetKicks Shout it

In my professional life I'm finding it's more and more common for me to be working with a legacy code base. Whether that's because a system we've written is simply long-standing and has become legacy or whether it's because we've inherited a system to support and maintain, the problems you encounter are pretty similar. However I think it's worth pointing out one of the major differences, and why it's sometimes better to be involved in the latter situation rather than the former.

I'm a big fan of egoless programming but trying to separate people from their code can be hard to achieve. Indeed, if you were responsible for creating the system that has become legacy it can be extremely difficult to be entirely honest with yourself about what state the system is in. Now that's not to say people cannot admit their own mistakes, just that sometimes because your head is filled with all the history of why certain decisions where taken it can be difficult to look at things entirely objectively. Ultimately, the system is where it is and how it got there is relatively unimportant.

As it transpires though, I'm currently involved in working with a legacy system where I've inherited the code. The original developers are gone and whilst their experience and skills are most definitely missed, their absence allows a certain amount of freedom in moving things forward.

I think being able to look at a system without the baggage that often builds up helps in two ways:

  1. You don't have any pre-existing priorities about the things you want to fix - I know that whenever I deliver any system there are always things I'm not happy with and this can sometimes cloud my judgement about what is really important.
  2. You don't worry about upsetting anyone - I know from painful experience that developers can be sensitive souls and sometimes they simply cannot be separated from their code.

So from my experience I'm convinced that it's always nicer not to have had a hand in the original system development if you're going to moving it forward...

Submit this story to DotNetKicks Shout it

I've just recently download Windows Live Writer to help me out with my blog posting.... maybe it'll make me write more stuff! 

This is just a wee test post to make it works like I want.

Submit this story to DotNetKicks Shout it

NAnt vs MSBuild

I like to use NAnt for building my .Net projects.

I am not a huge fan of the IDE (Visual Studio), but I am well aware that I am in the minority here.

So if I plan to use NAnt on a project, I've got to do it in such a way that the other developers can still use the features of the IDE, mainly intelli-sense and the Error List window.

I've been using a very small .csproj file (described below) which calls out to NAnt, and a small custom MSBuild task to log errors so that the IDE will display them correctly.

Adding the source-code

Starting with a blank project file, you can add all the C# files with a single MSBuild entry like this:

<Compile Include="**\*.cs" />
        

And that's it! Now you can browse all your C# code using the solution explorer. The intelli-sense will recognise your classes and start auto-expanding as you type.

I typically add nodes for each file-type I want to be able to edit: .cs, .build, .xml, .config, etc.

Intelli-Sense

The IDE will use intelli-sense for the classes defined in your C# code files. You also want it to pick up external references. Add a line for each reference you need intelli-sense for in another ItemGroup:

<Reference Include="NHibernate" />
        

The IDE will look for the assemblies under the path defined in the <OutputPath> node near the top of your project file. If you want, you can add a <HintPath> sub-element:

<Reference Include="NHibernate">
    <HintPath>SDKs\NHibernate\NHibernate.dll</HintPath>
</Reference>
        

Now you'll have intelli-sense for your referenced assemblies too.

Running NAnt

When Visual Studio builds it runs the 'DefaultTargets' for the project (usually an MS-defined target named 'Build'). When Visual Studio cleans it runs a target named 'Clean', and when it re-builds it runs the target named 'Rebuild'.

You can change the 'DefaultTargets' for the project at the top of the project file:

<Project DefaultTargets="NAntBuild" ...
        

Then add a target that uses the Exec task to call NAnt:

<Target Name="NAntBuild">
  <Exec Command="SDKs\nant-0.85\bin\NAnt.exe" />
</Target>
        

Now the solution will build using NAnt. Add targets for 'Clean' and 'Rebuild' too if you want to do these via NAnt.

Note, when you customise your targets the IDE will give you a security warning. Since you customised it yourself, you can safely ignore this warning.

Error List

So far this works, but build errors are only found by examining the output window. It would be nice to have errors reported in the 'Error List' window so that you can just double-click them.

We wrote a custom MS-Build task called ExecParse, which inherits from 'Exec', to allow parsing of of the output and logging errors to the MS-Build engine.

The configuration for ExecParse takes a regular expression to search the output for, and allows logging of errors using text from captures in the regular expression.

A typical compiler error looks like:

[csc] c:\...\MyFile.cs(24,60): error CS0246: ...

So we can create a regular expression that captures this, and log an error using the MSBuild engine:

<UsingTask AssemblyFile="...\ExecParse.dll"
           TaskName="ExecParse.ExecParse" />
...
<PropertyGroup>
  <ExecParseConfiguration>
    <Error>
      <Search>\[csc\] (.*?)\((\d+),(\d+)\): error …
        ([^:]*): (.*?)[\n\r]</Search>
      <File>$1</File>
      <LineNumber>$2</LineNumber>
      <ColumnNumber>$3</ColumnNumber>
      <Subcategory>$4</Subcategory>
      <Message>$5</Message>
    </Error>
  </ExecParseConfiguration>
</PropertyGroup>
...
<Target Name="NAntBuild">
  <ExecParse Command="SDKs\nant-0.85\bin\NAnt.exe"
           Configuration="$(ExecParseConfiguration)" />
</Target>
        

Now you have a NAnt build, building within the IDE, using intelli-sense, and logging errors to the 'Error List' window.


Some links:

Submit this story to DotNetKicks Shout it

Introduction

NHibernate uses an Identity Map to maintain a single instance of each persistent entity in memory. This allows you to run round a domain model without having to worry about which instance of an entity you are modifying.

NHibernate also uses Lazy Load. The default implementation for this uses Dynamic Proxy (DP) to generate a class at runtime that inherits from your real class. This generated class intercepts all of the overridable methods and properties in your class to load the instance from the database if required.

What Identity Map Allows

Identity Map allows you to load up the same object twice but to have your references point to the same underlying instance.

The following example NUnit test demonstrates loading 3 objects, two of them with an ID of 1, and the other with an ID of 2:


[Test]
public void TestIdentityMap()
{
    MyClass myInstance1 = Session.Load<MyClass>(1);
    MyClass myInstance2 = Session.Load<MyClass>(1);
    MyClass myInstance3 = Session.Load<MyClass>(2);

    Assert.AreSame(myInstance1, myInstance2);
    Assert.AreNotSame(myInstance1, myInstance3);
}
        

The following diagram shows how the references relate to the objects created on the heap.

The Identity Map ensures that there is only one instance of the object with ID equal to 1 in memory.

Under the hood of NHibernate

The basic principle of Identity Map is easy to pick up. However, there is a further complication because of the implementation of the proxies used for Lazy Load.

When you ask NHibernate for an object, it returns you a instance of a class created at runtime by DP. This class intercepts any overridable methods/properties and redirects them to a second object instance that has the 'real' class type.

So in the above example, the following is actually created on the heap:

Limitations of the current implementation

Since there are really two instances created on the heap when NHibernate gives you a proxy, there is an identity problem that you could run into.

Problem 1, the 'this' pointer:

Consider the following class:


public MyClass
{
    public virtual bool IsMe(MyClass anotherMyClass)
    {
        return anotherMyClass == this;
    }
}
        

The following test will fail because the reference myInstance points to the proxy, while the 'this' pointer is the real class:


[Test]
public void TestIsMe()
{
    MyClass myInstance = Session.Load<MyClass>(1);

    Assert.IsTrue(myInstance.IsMe(myInstance));
    // The above line will fail
}
        

It is easy to imagine an example where a child entity notifies its parent of an event, and the parent then updates all its children except the child that initiated the event. The parent or child might have to be careful about reference comparison in such an example.

Problem 2, private methods/fields:

NHibernate relies on DP intercepting access to an instance of a class, and redirecting these calls to the 'real' instance. However DP is powerless to intercept private field and method access.

Situations where this could occur might be:

  1. sibling objects of a common parent object that communicate with each other;
  2. parent/child objects of the same type that communicate with each other (e.g., a tree);
  3. static methods that reference an instance of the same type.

Consider the following class:


public MyClass
{
    private int _calculation = -1;

    public virtual int Calculation
    {
        get { return _calculation; }
    }

    public static void SetCalculation(
                                MyClass instance,
                                int calculation)
    {
        instance._calculation = calculation;
    }
}
        

The following test will fail because the static method sets the field not on the 'real' class but the proxy object, while the property accessor is intercepted and redirected to the 'real' instance.


[Test]
public void TestCalculation()
{
    MyClass myInstance = _session.Load<MyClass>(1);
    MyClass.SetCalculation(myInstance, 7);

    Assert.AreEqual(7, myInstance.Calculation);
    // the above line will fail
}
        

It is not uncommon for a class to have an interface for talking to other instances of itself while keeping that interface private from outsiders.

Conclusion

I suspect NHibernate could be improved to make the proxies self-proxy. If this could be done then there would be no second instance created, and no potential identity problem.

To avoid problems with the 'this' pointer, simply try to avoid using it for comparison with another object.

To avoid problems with one instance of a class talking to another instance of the same class, prefer virtual methods over non-virtual ones to allow Dynamic Proxy to intercept any calls made on the instance. (i.e., avoid using private fields or methods from one instance to another instance of the same class.)

A complete example of the above, with failing NUnit tests, can be downloaded here: NHibernateProxyDemo.zip

Submit this story to DotNetKicks Shout it

NAnt Tasks

NAnt allows you to combine tasks to automate your build process. Tasks can be grouped together into targets, and targets can call other targets (much like functions/methods in any other language).

If you need to do something that cannot be done by an existing task, you have two options:

  1. Create a target that combines existing tasks;
  2. Write a custom NAnt task.

Option 1 has some limitations; you can create a target, give it a name, and call it in your script by using <call target="myTarget"/>. However, the target cannot specify a list of parameters, so you have to rely on setting (agreed) properties before calling the target if you want to pass information to it.

Option 2 allows you to create a new task for NAnt. They are considerably more effort to write and maintain as they need knowledge of a .Net language (e.g., C#). If you want to do something that cannot be done by existing tasks, then they are probably your only option.

Sometimes you want to write a task that can be done with existing tasks (e.g., check a target is up to date; if it isn't, code-generate some code, compile it, and register the assembly in the GAC), but without resorting to C#. We thought a middle ground would be nice, so we wrote a couple of custom NAnt tasks that allow you to create new custom NAnt tasks that are written using regular NAnt script.

Enter NAntScript

NAntScript is an open source project we wrote to allow NAnt users to script custom NAnt tasks using only existing NAnt tasks (no C# required).

Two custom tasks are provided:

  • taskdef - defines a scripted custom task;
  • tdc - compiles a collection of taskdef nodes in files into an assembly.

Now you can write custom NAnt tasks without resorting to C#.


Submit this story to DotNetKicks Shout it

Introduction

Every software project needs to gather requirements, perform analysis and design, implement, and finally deliver a working system.

These days we have a lot of tools to get us through the implementation and delivery, from TDD through to automated installers (e.g., WiX). We have a maturing vocabulary of Design Patterns to aid communication in a design phase. However analysis is often left as a hand-waving exercise with less clearly defined tools and methods.

Gathering Requirements

All too often the requirements gathering is merely verbatim recordings of wish lists dictated by the customer. These requirements are often recorded by people with lofty titles such as Business Analyst; ironic considering they rarely contain much, if any, analysis of the problem.

The requirements lists are usually driven out of a more traditional waterfall style development, and serve two main purposes:

  • define the scope of the functionality;
  • define a contract.

The first of these points (scope) cannot be defined up-front. Software development is now recognised as new product development, and not a manufacturing process. Requirements change. Always. The way to confront this problem is to gather a few requirements at a time, implement, deliver, and iterate.

The second point is born out of a naïve company's need to be able to prove that what they have delivered is legally acceptable, despite the fact it will invariably not be what the customer wants. The preference should of course be for "customer collaboration over contract negotiation" [Agile].

The interesting question to ask when confronted by one of these bullet-list style requirements documents is "how does this help me solve the problem?" These documents rarely (if ever) contribute to a solution - instead they allow nervous project managers to relax contented in their ignorant belief that the solution can be proven correct.

Turn to an Alternative

So we know to avoid requirements lists. We are educated enough to use a more modern approach to documenting requirements such as use cases, user stories, scenarios, etc. Typically I choose use cases. All we need to do is describe the steps that an actor performs to complete a task, then we have accurately described our requirements, right?

Well, perhaps ... but ... it's still not necessarily analysis.

These could still essentially be verbatim recordings of the customer's description of how a given actor performs a task. But if that's all that is recorded then you've missed a trick - you've missed the opportunity to actually analyse the problem and start down the road to a solution.

Note: I am not suggesting that these use cases are useless, just that they could be so much more. If someone's already done this work then it can still be useful for verifying that delivered software actually solves the problem at hand. However, without analysis, they still don't provide progress to a solution.

Ubiquitous Language

The task of analysis is to define the objects in your proposed model. Rather than just defining them then forgetting them, instead they should become the nouns that you continually use when discussing functionality.

Use these nouns when discussing requirements with the customer. Use them when writing your use cases. Use them in every technical note, and every phone call. In short, use them everywhere; they then become the Ubiquitous Language [Evans] of the system.

Building the analysis model is a creative process, and as such does not have easily defined rules. Often the customer will already have names for items in the problem domain; these might translate directly to objects in the analysis model. Other times the customer might have several different names for related items, and it is the job of the analyst to abstract these to a single object in the analysis model. Often the customer will have concepts that require a new noun to be invented. These are the tools of the analyst: mapping, abstraction, and invention.

In addition to using the Ubiquitous Language, the language should be persisted along with any other documentation. It may be defined using a UML class diagram. It may be defined using a dictionary/glossary style document. It may be a combination of a class diagram and supporting text. What is important is that the definitions are concrete, and presentable to the customer.

Once the initial model is in place, the use cases can be fleshed out. It is important that the use cases use the language of the analysis model. This starts to extract the actions that can be performed the objects, and starts to highlight the relationships and constraints between them.

The process of defining the model, the objects and their relationships, the properties of the objects, the actions that can be performed on them, and the constraints on their use - that's analysis.

A Simple Example

Suppose we take a look at the process of hill-starting a car (we'll assume for simplicity it's an automatic).

The use case (recorded verbatim) might read:

  • Actor starts the car;
  • Actor secures the car, and puts it in gear;
  • Actor checks there's nothing coming;
  • Actor allows the car to move off.

Okay, so it's a slightly artificial example - but that's only obvious to us because we know what a car is, and how it works. If we'd never seen or heard of a car before, then we wouldn't know whether these steps read appropriately or not.

This use case describes the process of getting the car moving, but does not bring us any closer to designing a car. Instead we should be analysing the scenario to try and extract the key objects in the domain.

If we start asking questions as to how someone starts the car, we might come up with the idea that a car has a "starting component" - we might even make the jump to calling it an "Ignition". We now have our second object in the domain (the first was a Car), we have a relationship defined (a Car 'has an' Ignition), we might define the actions (activate?), and a constraint (the Ignition can only be activated when the Car is not already started).

We might very quickly end up with a rich new language (Car, Ignition, Brake, Gear Stick, ...), the relationships between them (a Car 'has a' Brake), some constraints (the Gear Stick is in one of park, drive, ...), and the actions that can be performed on them (the Brake can be 'applied'). If we'd never seen a car before, the analysis might need to invent a new name for an item - although we're comfortable with the term nowadays, do you think the first person to hear the pedal called an "Accelerator" though it was an ideal name? I doubt it, but it has become an accepted part of the Ubiquitous Language of driving a Car.

The use case might now read:

  • Actor activates the Ignition;
  • Actor applies the Brake, and moves the Gear Stick from park to drive;
  • Actor views the Mirrors; (needs an exception scenario for when they're not empty)
  • Actor releases the Brake, and applies the Accelerator.

Notice the nouns are capitalised. Notice there are clearly defined verbs on the nouns. We are now a step closer to building a car; we know what a car has, and can start to design some of its components. We have something that is giving us a step towards a solution.

Summary

Define the nouns, and use them religiously, not just in your use cases, but in every conversation you have with the customer. Describe the relationships between the objects in this model, and the constraints. Construct your use cases using these names as proper nouns, defining the kinds of operations that can be performed.

If you do this you'll have analysed the problem, and proposed a solution.

Avoid bullet-lists of requirements recorded verbatim. They try to limit scope. They try to define a contract. In short, they are anti-agile!


Submit this story to DotNetKicks Shout it