jeudi 3 juin 2010

3 days with Greg Young

IMG_2720 Last week Pyxis hosted an intensive three days immersion into Greg Young's Applied DDD course. This course is amazingly packed with tips and tricks on how to come up with an architecture that delivers business value customers have come to expect from their investments in software systems. Powered by Greg’s energetic tone, this course challenged my assumptions of how software should be designed and I would recommend it to anyone interested in architecture innovations surrounding Domain Driven Design. Following is an overview of the topics we’ve tackled during the training.

DDD recap

The first day was spent refreshing some of the fundamental but often misunderstood concepts of Domain Driven Design. We were reminded that Strategic Design is essential while embarking on a Domain Driven Design project as we must make sure that the value we get out from it is well worth the effort. Notions such as Bounded Contexts and Core Domain allow highly knowledgeable teams to focus on value added development work while leaving less crucial aspects of the software to others.
Another topic that stroke a chord with me was Greg’s presentation of Aggregates and the role the play in well crafted software systems. Aggregates exist to provide transaction boundaries around the behaviors of domain objects. Aggregate roots provide the sole entry point to this grouping of domain behaviors and encapsulate validation logic as well as invariant consistency inside the aggregate.

CQRS

EventSourcingWe spent the second day learning about Command Query Responsibility Segregation and Event Sourcing. CQRS is different then Command Query Separation (Bertrand Meyer) which advocates that methods that change state should be separated from functions that return value. CQRS takes the same principle and applies it to the hole architecture. In this style of design some objects (write model) represents the commands the domain respond to and other objects (read model) handles the queries and their results. Having separate models for these concerns brings a lot of benefits that I will bring up in later posts.
The write model
It’s common OO knowledge that objects should be designed around behaviors in a domain. Having a dedicated write model consisting of aggregates that define transaction boundaries around the behaviors in the domain focuses work on the most valuable part of the system. This is the place to maximize the return on the work of your most skilled developers aided by domain experts.
The read model
The query side doesn’t have a domain as it’s mostly straightforward boilerplate code. The preferred implementation of a read model is having request DTOs going through a thin query layer that projects directly off of a data source. This is way simpler that using the domain model to do the same. This way pre-fetched paths and optimizing ORMs queries are avoided.
Event Sourcing
Event sourcing can be seen as a way to “standardize” thus reduce the cost of implementing separated read and write models. The basic idea is that all domain can be modeled as receiving commands that and producing associated events. These events can be stored as a log of what happened in the system and also be used to update the read model.
IMG_2717 While exposing concurrency issues and ways to handle them Greg showed us a merging algorithm that’s quite simple and clever. Probably, the only piece of code Greg would ever write with a Goto statement as you can see in the picture.

Fine tuning the architecture

The third day was spent analyzing the properties of this architecture and how it could be fine tuned to produce low latency, high availability and high reliability systems. Most notably CQRS architecture can used to get around CAP theorem issues which states that you can’t guarantee all three Consistency, Availability and Partitionability in one system. Look here for another treatment on how to get around CAP.
All these architecture talks made me realize that using DDD and CQRS is a lot of work. And it’s no wonder that they should be applied to core domains. Now most companies I’ve worked with deal with multiple domains such as Sales, Security, Insurance, etc... And it would have been difficult to single out the one that constitutes their core domain. But every company must have a core domain otherwise it would not have a competitive advantage. Turns out a lot of companies derive their competitive advantage from their business process that integrate all of the domains they deal with. This is the place their core domain reside and that’s where Sagas help.

Pyxis source of high quality technical learning

IMG_2719 All in all, these three days were packed with useful technical knowledge and eye opening discussions with an expert in his craft. The participants enjoyed the learning experience in Pyxis’ agile environment where they got a close up look at our facilities supporting agile teams. Pyxis is proud to have sponsored this event and is dedicated to bringing high quality technical training to the public.
Other technical trainings :

lundi 3 mai 2010

My presentation at the Toronto Code Camp 2010

I had a blast meeting new people and sharing experiences writing software. I especially liked Barry Gervin’s keynote on successful product management and Todd Anglin’s talk on HTML5.

As for me, I did and introductory talk on Scrum and Visual Studio 2010 briefly touching on some of the content of the Professional Scrum Developer course. The training has already started in several countries around the globe: Brazil, Australia and US. I’ll be teaching the Montreal edition that’s coming in June 7th. It’s going to be awesome!

About the Professional Scrum Developer Course

The Scrum Developer course is a unique and intensive five-day experience for software developers. The course guides teams on how to turn product requirements into potentially shippable increments of software using the Scrum framework, Visual Studio 2010, and modern software engineering practices. Attendees will work in self-organizing, self-managing teams using a common instance of Visual Studio Team Foundation Server 2010 to achieve this goal.

Course attendees are prepared to take an assessment at course completion and then become Certified Professional Scrum Developers.

jeudi 25 mars 2010

Professional Scrum Developper Training

Dates are now open for the Professional Scrum Developper on the .Net platform training in the Montreal and Toronto areas. This training is fully packed with knowledge and hands-on exercices that are important for today's developers, architects and testers working in agile teams. 



Scrum Developer course is a unique and intensive five-day experience for software developers. The course guides teams on how to turn product requirements into potentially shippable increments of software using the Scrum framework, Visual Studio 2010, and modern software engineering practices. Attendees will work in self-organizing, self-managing teams using a common instance of Visual Studio Team Foundation Server 2010 to achieve this goal.
Course attendees are prepared to take an assessment at course completion and then become Certified Professional Scrum Developers.
You can register via scrum.org

Hope to see you there!

samedi 20 mars 2010

Professional Scrum Master Level II

I've just received confirmation from Ken Schwaber that I've successfully completed the Professional Scrum Master Level II assessment available on Scrum.org. I'm very proud of announcing that I'm also a .Net  Professional Scrum Developper Trainer and that I will be delivering this course in Canada in May and June. Stay tuned for the official dates.

jeudi 18 mars 2010

Automated Unit Tests as Documentation

Introduction

In our quest to produce quality software and our relentless use of automated unit tests in our development activities, we’ve come to realize they possess other virtues as well. One of those being they stand as a documentation of the system being developed. I’ve taught this idea in several agile and TDD courses. In this blog I want to give you an example of how that may be. I’m purposely not discussing executable specifications and Behaviour Driven Development as it would make this blog too long. My goal is to show how using some convention and Visual Studio 2010 can go a long way in cranking up your unit tests another notch.

Documentation of API usage

One clever use of unit tests is for learning a new API or even a new language. Writing several assertions to validate our understanding and assumptions about an API usage is very rewarding as the feedback is rapid and progress towards a goal is constantly measured. These learning tests may be kept around to document the assumptions made that constitute the basis of our solution. Here is an example of a learning test for the Character.IsWhiteSpace() method of the BCL.
[TestMethod]
[Description(@"White spaces are the following characters: ' ', '\t', '\n', '\r'")]
public void May_be_a_white_space()
{
    Assert.IsTrue(char.IsWhiteSpace(' '));
    Assert.IsTrue(char.IsWhiteSpace('\n'));
    Assert.IsTrue(char.IsWhiteSpace('\t'));
    Assert.IsTrue(char.IsWhiteSpace('\r'));

    Assert.IsFalse(char.IsWhiteSpace('A'));
    Assert.IsFalse(char.IsWhiteSpace('+'));
}

A test can also document how to use the classes we create in our solutions. The following is an example of such a test. In our chess software, this unit test documents the way of obtaining a chess piece which is to call the NewPiece() factory method and passing it a color (either Color.White or Color.Black) and a Kind (such as Kind.Pawn) as arguments.
[TestMethod]
[Description("A chess piece consists of a kind and a color that are specified when the piece is created")]
public void Should_retain_its_color()
{
    Piece pawn =
           Piece.NewPiece(Color.Black, Kind.Pawn);
    Assert.IsTrue(pawn.IsBlack);
    Assert.IsFalse(pawn.IsWhite);

    pawn = Piece.NewPiece(Color.White, Kind.Pawn);
    Assert.IsTrue(pawn.IsWhite);
    Assert.IsFalse(pawn.IsBlack);
}

Documentation of behaviours

Unit tests document behaviours of our code. Test classes should  be given names that provide context for all the test methods they contain.
[TestClass]
public class When_displaying_a_board
{
    [TestMethod]
    public void A_black_queen_should_show_as_Q()
    {
        …

    }
   
}

Test methods should also be named in such a way that the behaviour they validate is evident.
[TestMethod]
[Description("The board is displayed on 8 lines with blacks pieces on line 8 and 7 and white pieces on lines 1 and 2")]
public void It_should_show_all_pieces_in_their_initial_position()
{
    Assert.AreEqual(
        "RNBQKBNR".Line() +
        "PPPPPPPP".Line() +
        "........".Line() +
        "........".Line() +
        "........".Line() +
        "........".Line() +
        "pppppppp".Line() +
        "rnbqkbnr".Line(),
        board.ToString()
        );
}

Notice that, instead of writing comments, I’m using the Description attribute to tie the behaviour being tested with some requirement or specification of the system. Personally, I’m not doing anything fancy with these descriptions, but you can imagine using a pattern that would provide more traceability in your environment as in the following.
[TestMethod]
[Description("US 234: Black pawns are shown as P, white pawns are shown as p")]
public void A_white_pawn_should_show_as_p()
{
    Piece whitePawn = Piece.NewPiece(
                        Color.White,
                       
Kind.Pawn);
    Assert.AreEqual("p", whitePawn.ToString());
}

Documentation of design specifications

Now comes the fun part! Because of the thought we’ve put in selecting meaningful names when the tests are executed in Visual Studio we get a result screen that looks like this.


Notice how combining our test class and method names reads like a phrase that documents the design of our software. If we group the results by Description, we get a list of all the requirements of our software.


If we expand one of the requirements, we see all the tests that validate it so we can trace back to the code that implements it.

Conclusion

I hope I’ve convinced you that tests can serve as documentation using simple tricks, conventions and tooling you may already have at your disposal. Because this documentation is embedded in code it has a lot more chance of being maintained as the code evolves. These techniques require agreement amongst team members but they foster good practices of choosing explicit names and tying development work with planning activities for traceability purposes.

jeudi 11 mars 2010

Coding and Debugging in Bubbles

A new concept for the modern IDE, Code Bubbles allows developers to see and work different fragments of code as one unit. Debugging sessions can be associated with those units save and retrieved later for continued work. Quite impressive! It’s really a departure from the IDEs we’ve been using so far. Of course, this is not mainstream yet. Nevertheless,  I would like to try something like that and it would probably be interesting to have the equivalent in the .Net space.
I have to wonder though, what the impact will be on Object Oriented Programming and encapsulation if developers are lead to think of their code as fragments of functionality scattered in their code base…