Saturday, April 16, 2011

MIX 2011: WCF, OData, MVC, and MEF Highlighted Presentations

MIX 11 has finished. Here are the presentations that I will be "diving into" more quickly than others.


My Summary of Summaries:

The topics below caught my eye as priority because:
  • They build upon OData, and thus upon Atom and REST . REST is the foundational architecture of the WWW, and is still not widely understand throughout the entire development industry
    • I'm likely to be joining a large project that will be providing enterprise wide alerting, notification, and reporting capabilities to X number of organizational sub-units. It's critical that interfaces to such services be simple, document-based, and that output data be consumable by end-user tools like Excel. OData support is "baked in" to the latest Office products and into Sharepoint 2010.
  • Regarding MVC and MEF: these two technologies are critical for modular, extensible web applications on the .NET platform. Being able to deploy sub-units independent of an independent application architecture is critical both for ease of maintenance and extensibility, but is also important in highly secure environments that require rigorous application scanning for security threats.
That's more than enough from me. I'll let the experts Castro and Block elaborate :)

Scott Guthrie's key-note, naturally:

Why: because it's The Gu. Period. Full-stop.

Pablo Castro on OData Roadmap: Powering the Next Generation of Services:

Summary:

At home and work, the way we experience the web (share, search and interact with data) is undergoing an industry-changing paradigm shift from "the web of documents" to the "web of data" which enables new data-driven experiences to be easily created for any platform or device. Come to this session to see how OData is helping to enable this shift through a hands-on look at the near term roadmap for the Open Data Protocol and see how it will enable a new set of user experiences. From support for offline applications, to hypermedia-driven UI and much more, join us in this session to see how OData is evolving based on your feedback to enable creating immersive user experiences for any device.

OData Roadmap: Exposing any Data Source as an OData Service: http://channel9.msdn.com/Events/MIX/MIX11/FRM16

Summary:

Many of the popular OData services, including Netflix, Twitpic and Facebook Insights were built by reusing their existing web API with an OData service. Implementing this type of OData service is not simple but it's also not as hard as you might think. In this session, you'll learn how to build similar services that wrap different types of data sources using the WCF Data Services Toolkit. We'll take a look at the implementations for several of the popular services as examples of how to use the toolkit to create new OData services.


Summary:

So you have a team of developers… And a nice architecture to build on… How about making that architecture easy for everyone and getting developers up to speed quickly? Learn all about integrating the managed extensibility framework and ASP.NET MVC for creating loosely coupled, easy to use architectures that anyone can grasp.

OData in Action: Connecting Any Data Source to Any Device

http://channel9.msdn.com/Events/MIX/MIX11/FRM10


Summary:

We are collecting more diverse data than ever before and at the same time undergoing a proliferation of connected devices ranging from phone to the desktop, each with its own requirements. This can pose a significant barrier to developers looking to create great end-to-end user experiences across devices. The OData protocol (http://odata.org) was created to provide a common way to expose and interact with data on any platform (DB, No SQL stores, web services, etc). In this code heavy session we'll show you how Netflix, EBay and others have used OData and Azure to quickly build secure, internet-scale services that power immersive client experiences from rich cross platform mobile applications to insightful BI reports.

Glen Block on WCF Web Apis: There's an URI for That: http://channel9.msdn.com/Events/MIX/MIX11/FRM14

Summary:

Web application developers today are facing new challenges around how to expose data and services. The cloud, move to devices, and shift toward browsers are all placing increasing demands on surfacing such functionality in a web-friendly manner. WCF's Web API makes it easy for developers to expose their services and data to a broad set of clients and to take advantage of rich emerging web standards like Web Sockets.



Tuesday, April 5, 2011

Delivery and Simplicity : Don't Leave Home Without These Agile Principles

Bootstrapping Agile from the Trenches

In February of 2006, I was offered the position of Lead Architect for the redevelopment of CDC's Epi-X system, CDC's flagship secure communications platform for emergent disease outbreak notification and bi-directional collaboration between multi-jurisdictional public health authorities. However, on the same day I was offered a position at a private .NET consulting company, Abel Solutions. Realizing that actual redevelopment of Epi-X would be months, if not years away, due to the then very disruptive agency-wide reorganization, I decided to leave so that I could gain more experience in a variety of private sector industries.

During the five years since I left Epi-X, I've worked as a senior software engineer, architect, lead application architect, and as an independent consultant. My first assignment with Abel Solutions was to re-architect and re-develop a very popular web-based electronic commerce & auction system to support more than 1 million registered users and the processing of more than 300 million dollars in annual sales. For a different company,  I re-engineered the security, object-relational, and querying architecture of a complicated human resources & payroll processing system used by thousands of companies. Most recently, I helped lead the design and development of both a modular user-interface architecture and the core service-oriented architecture for a new correspondence banking & ACH settlement platform to be used by hundreds of local and regional banks to conduct business more easily with the Federal Reserve and each other.

For the companies sponsoring the first two projects mentioned above, I introduced and lead the successful adoption of Agile management and development practices. For the third, I was recruited specifically to consult both on their adoption of Agile and the design of its new system's user-interface and service-oriented architecture.

I've also consulted with many other private entrepreneurial businesses about technology strategy, and in 2008 founded both the Atlanta Science Tavern and the ATL ALT.NET community groups.

Aligning the Agile Approach to the Business Domain

Let me be the first to state that adopting Agile in the "real world" is not easy. To be successful, you must internalize the values of Agile, especially the very first one which reads:

Our highest priority is to satisfy the customer

through early and continuous delivery

of valuable software.

Did you notice that this specifies nothing whatsoever about writing code? It specifies nothing at all about writing code at all. It specifies delivery of valuable software.

Later on in the principles document, it says:

Simplicity--the art of maximizing the amount

of work not done--is essential.

It says simplicity is essential, not optional, but essential. How many projects have you seen that feature unnecessary complexity? That is the exact opposite of this Agile principle. For more about this problem, see my post that reviews a Skype architect's presentation.

You can read the rest of the Agile principles here: http://agilemanifesto.org/principles.html

I highlight this because a lot of practitioners think that Agile is some kind of magic bullet that will solve all the problems that sequential "waterfall" style development has. This is absolutely not the case.  Agile has its own pitfalls that must be addressed as well, and one of them is plainly that development teams don't even understand or truly believe in these two core principles!

The Core of Agile: Communication and Collaboration

As the principles in the Agile Manifesto explain, collaboration and communication are the two most critical underlying themes of agile development. What if, by communicating with your clients successfully you could help them avoid spending millions of dollars custom-developing a solution to a problem that you could solve using low-cost or open-source software?

Would that not be the ultimate fulfillment of the first principle of Agile? I think it most certainly would. And, it would certainly fulfill the later example I highlighted!

Unfortunately, many people, even managers, fail to think this way when they adopt Agile. This is not to say that they don't mean well. It's often just the case that they recognize Agile, and associated development practices like XP and TDD, as a better way of building software, but can lose sight of principle number one: delivery of valuable software.

Internalized Agility = Flexibility

True internalization of Agile values should cause architects, developers, testers, and all manner of managers to adopt an attitude of true collaboration with their stakeholders.

So, keep it mind that being agile doesn't always mean building software. First and foremost, it means delivering valuable software.

Tuesday, March 29, 2011

New Reading List: Acceptance Testing, Specification by Example

As usual, there are far, far too many topics that interest me than I will likely be able to comprehend.


I'm extremely interested in recent presentations and work from Gojko Adzic.

I'm going to buy his books Briding the Communication Gap and Specification by Example:



You can see Gojko present about these topics in numerous places, including:




Why do these topics interest me? The easy answer is that I find it very painful, both mentally, and physically to endure lapses of communication in projects that lead to lost time, money, or functionality when I know in my heart such problems can be avoided with proper communication.

Scott Ambler has also written extensively about Executable Specifications at http://www.agilemodeling.com/essays/executableSpecifications.htm

These ideas bring together the two aspects of system development that matter most to me:
  • Achieving the correct result for my customer / user
  • Seeing something valuable running
Nothing is more crucial to my sense of accomplishment when building a system than to see the correct result in action.  I know, however, that many teams value "documentation" as a very important communication artifact that serves to mediate between "the business" and "the development team", but I find this to be a source of constant frustration for the very reasons that Gojko lays out. Instead, what is more valuable, and very satisfying, is to execute the documentation, the specification, the requirements in a testable, verifiable way that itself represents real tangible value, not just words on a dead sheet of paper.

Gojko's presentations are excellent and his books look like they will really fill the "gap" in my own arsenal. I am looking forward to devoting significant time to studying these works.

As he explains on his web site, here are the "Key Ideas" in the Bridging the Communication Gap book:







Monday, March 28, 2011

Strangulation: The Pattern of Choice for Risk Mitigating, ROI-Maximizing Agilists When Rewriting Legacy Systems


"The most important reason to consider a strangler application over a cut-over rewrite is reduced risk. A strangler can give value steadily and the frequent releases allow you to monitor its progress more carefully. Many people still don't consider a strangler since they think it will cost more - I'm not convinced about that. Since you can use shorter release cycles with a strangler you can avoid a lot of the unnecessary features that cut over rewrites often generate." -- Martin Fowler, Chief Scientist, ThoughtWorks, on The Strangler Pattern

When rewriting a system in a new technology, it's tempting to think that the task will be easier and quicker than the first time it was written. Because of this, sometimes business sponsors believe that a "waterfall" or "big bang all at once" approach will work out, but this is rarely the case for any project large enough and important enough to warrant rewriting. It's always important to practice iterative and incremental development to provide for feedback loops. But, it's even more important to do this in the case of a large application rewrite. This article will explain why this is true. There are a few bedrock development principles that project sponsors and team members should put into practice to ensure the success of large scale migrations. Having learned these lessons from experience, these are:
  1. Involve business sponsors and end-users directly (or a user-experience specialist) and the entire support and operations teams during the entire rewrite
  2. Involve permanent quality-assurance professionals from the beginning and during the entire rewrite
  3. Design, code, and test one complete feature rewritten from the existing system as quickly as possible
  4. Thereafter, design, code, test, and pilot user-valued, return-on-investment-generating (ROI) features in small increments
  5. Most importantly, continuously build team member skills, knowledge, and leadership abilities

Lessons Learned in Rewriting Large Legacy Systems 

In February of 2006 I joined a small .NET consulting company. Shortly thereafter I was assigned to a brand new project for one of their clients to analyze, design, and develop a new version of an existing electronic commerce platform. The system was a highly successful, niche-market leading auction site with nearly 700,000 registered users at the time. In operation for more than seven years by then, the system was built on classic ASP, C++/COM, and SQL Server 2000. It consisted of about 330 ASP pages. Our client wanted to do two primary things. First, he wanted to add new, value-added features to the system to provide a much better user experience, one that would be similar to eBay. These features would be called "My Auctions". This new set of features would take the place of roughly 30 pages from the existing web site. Second, he wanted to migrate the other 300 pages, without introducing any functionality or usability improvements, to ASP.NET WebForms. Having already personally designed and developed the entire business object back-end COM objects, he wanted all of the new web site to reuse this investment by utilizing COM Interop.

My Recommendation: Perform a Phased, Vertical Migration One Piece at a Time

My first assignment was to analyze the existing ASP and C++ code to and produce a migration strategy recommendation. This strategy document would lay out our company's professional opinion for migrating the system to the .NET platform and the C# language. My recommendation was for our client to perform a vertical migration, which is a migration that incorporates an entire functional slice of a subset of the system (My Auctions) which cuts across all architectural layers (top-to-bottom). In their book The Pragmatic Programmer, Dave Thomas and Andrew Hunt call this a "tracer bullet". This was, in fact, what Microsoft recommended in their best practices guidance documents that I researched about performing large scale system architecture migrations. I recommended that our client hire us to build a new core platform on ASP.NET with C# and get the new, value-added features to market as soon as possible on top of that core platform. Only after these value-added features were in production would we then move on to replacing the rest of the 300 pages with ASP.NET replacements.

My Reasoning: Place Customer Satisfaction, ROI, and Risk Mitigation First

My reasoning was that by creating a new core platform and building the brand new, usability-focused, value-added My Auctions features on top of that, our client would generate a return-on-investment (ROI) much sooner by generating more sales volume with the user-friendly features and would simultaneously mitigate significant risk by testing the viability of the COM Interop strategy. By virtue of the features being value-added, there would be no risk whatsoever for him to deploy them to a parallel web server and get his users to begin pilot testing the system and providing valuable feedback early on in the game when he could still make significant changes prior to committing to replacing the entire system with the new technology.


I've since learned from Dan North at QCon 2010 in S.F. that is called The Strangler Pattern according to Martin Fowler, hence the title of this post!

Client Decision: Let's Do It All At Once

Our client considered my recommendation very carefully, but wanted to take a different approach. Rather than deploy the new My Auctions features independently, side-by-side with the existing system, he wanted to have his in-house staff work on the other 300 pages while our company worked on the value-added features. With more than 330 pages to complete, I estimated that the project would not take less than a year, but would more likely take two years or more to complete. Our client and my manager thought things could be done much faster if we had three or four people working on the system. This was certainly the case early on when I worked side-by-side with another developer in our company. Within four months, he and I had completed the new C# application foundation and the value-added features to the point that they were ready for beta-testing.

And that's when all the fun began!

Planning is Essential; Plans are Useless

As anyone who has worked in the software industry for a number of years knows, the best laid plans never go as you planned. Our client's lead C# developer left his company. Soon after that, my manager at my company was let go, but several months later he was hired by our client to take over the development management of the project. This made sense since he already had strong background on the project since its inception. Shortly after this, our client's HTML, graphics, and CSS developer quit when asked to change his focus to become an ASP.NET developer. They hired a lead C# developer and he got to working on a large slice of the application while I continued to work on another large slice. Five months later, they hired a second C# developer and he began working on several other slices of the application.

Wanting to see the project through to success, I joined the client as a direct employee to continue being the lead architect for the project.

Naturally, There's a Big Trade Show In The Story

What would any development story be without a "Big Trade Show" lurking around the corner? As luck and fate would have it, in early 2008 there was a huge industry trade show, and it was critical that we would be able to demonstrate the new version of the system to the roughly 25,000 customers that would be passing through our booth. And, it would be very important that these customers be able to see their own real items, either ones they were selling or ones they were buying. The problem was, of course, that the system was not ready to replace the production system! Due to security requirements brought about by a changing legal environment, we had to repartition the back-end database for the new system from 2 SQL databases into 6 separate databases just before the trade show. It was deemed too risky to perform this radical "surgery" on the live, production system just two months before the trade show. The new system's schema was about 95% the same as the old system, but there were corrections to long-standing column name problems or foreign-key reference inconsistencies. This was a complicating factor, however, for migration.

We tossed around various ideas, such as:

  • Perform the "surgery" on the production database to upgrade it to the new system schema, then use views and synonyms to create a "pass-through" database that looked like the old schema, but mapped across to the new DBs and structures.
  • Do the reverse: create several "pass-through" new databases with views and synonyms that actually resolved to the single existing production database's objects.
We felt that we could mitigate risk entirely by following the second option. What this also allowed us to do was to "override" some of the production system's tables with configuration data specific to the new system. The approach of using synonyms and views ensured that all writes and reads against the pass-through objects would actually resolve into the production database, thus enabling the beta version of the new system to live side-by-side with the legacy system.

The War Room

After some proof-of-concept prototyping, we realized this would be a winning strategy. Over the next couple of weeks, the four of us on the development team gathered daily in our "war room", and worked together to create all the necessary SQL scripts and shell databases, synonyms, views, etc that would be the magic glue. We ensured that we could re-run the scripts at will and automated our quality-control checks and sanity checks to be certain that all mappings would have proper permissions and configurations. After enough practice runs, we felt confident that it was ready to go. We created a single zip file which contained 5 BAK files, and a T-SQL script. We handed them off to our lead database administrator and he ran the scripts. Everything worked just as planned!

Cha-Ching!

At the trade show, everything went off flawlessly! Customers attended our booth and we, the development team, aided them directly in logging into the system and showcasing the new features we had worked so hard to develop. It was a very gratifying feeling to see how our improvised plan came together so well. Most importantly, we had succeeded in mitigating all risks to the money-generating production system, while also achieving the benefit of showcasing the new system to customers with real data. This was very exciting to them because they felt that the new features would greatly help them run their own businesses atop our platform.

Phased Transition From Legacy to New

We had now successfully demonstrated and validated the new, value-added features directly with customers in person. This was a great success. Yet, there was still much to do after the trade show. Features of lesser prominence, those in the 300 other pages set still needed to be developed and tested. This ended up taking a very long time, but we ultimately cycled back to my original recommendation by adopting an incremental replacement strategy.

It worked like this:
  • We deployed the new system to a new web server, named v2.
  • The existing, v1 site, remained at www.
  • We provided a link from v1 to v2 in the header of the v1 site, including advertising the benefits of the new system, but also including disclaimers and calls for assistance in testing and validating the usability of the new system.
  • This garnered a lot of early-adopters who helped find bugs and inconsistencies, all for free to us!
  • We monitored the usage patterns of v2 versus v1, to help estimate the load capacity under real-world conditions.
    • Michael Nygard's book "Release It!" proved prophetic here. In his book he says that "feature complete" is not the same as "production ready."
    • We learned this because the COM code had to be completely replaced with pure C# code since it could not stand up under load using COM Interop.
      • This result bore out my original advice to get the new features into production as soon as possible to monitor under real world conditions.
  • We formally adopted Scrum and Agile practices by identifying business-driven priorities and working through them in sprints.
    • We did this by closely monitoring the real-world usage of both the existing v1 system and the v2 system and focusing our effort first on the highest traffic pages, such as Viewing, Browsing, and Searching. Of course, Bidding and Payment, while producing less volume, were also mission-critical.
    • This focus allowed us to prioritize properly. We did not place inordinate emphasis on automating the testing of all areas of the system.
      • For example: we did not write Selenium test suites for things like Help Pages or Support Pages. Why? They are seldom used! And, they generate no revenue.
        • Instead, we built comprehensive Selenium test suites for the Big Four: Viewing, Browsing & Searching, Bidding, and Payment.

A Pleasant Surprise!

With the site now operating both in legacy, classic mode at www, and in "beta" mode at v2, the team began to actively monitor the new system's health health and encourage more and more users to jump into using v2. And, because we had focused on developing the value-added My Auctions features in the very beginning of the project, those features sat ready and willing to get into production! Our newest member of the team, who joined about two years after those features were ready and "shelved", took it on his own initiative, to our delight, to start building a mobile version of the core My Auctions features using ASP.NET MVC and the business objects that supported the My Auctions features. He was reluctant to show this prototype to the "higher ups", but the rest of our team encouraged him to do so. Within a few months, his mobile application was released into production before the global "switchover", described below, to the new system. A job well done!

Switching Over Right on Time for a Cool Billion Dollars

Over the course of more than a year, the team monitored the usage of v1 and v2, and began to more aggressively push the late adopters and stragglers into the new system. Eventually a "switchover" was made, and the v2 system took over the place of www. At that point, there was now a link back to v1, which ran from a virtual machine. Several months after this, the VM was retired, and the v1 system, and all of its legacy COM, was no more.

Just after the legacy system was retired for good, the company celebrated its 10th anniversary and 1 billion dollars in sales volume!

Retrospective

In retrospect, I spent nearly three years working on this project and learned a great deal! While I wish that the original plan of seeing the entire migration take place "all at once" could have been successful, I also am pleased that my original recommendation to take a phased, incremental, risk-mitigating, ROI-maximizing approach was very sound. Ultimately, that very approach became necessary due to the "expected" unexpected bumps along the road!

Application to Domains Seeking Non-Financial Returns

I understand that not all projects involve financial reward goals. Before I began working on the project just described, I worked for four years at the US Centers for Disease Control and Prevention. While working there, we were not seeking to generate financial return-on-investment. However, we did seek returns in the form of utility and value to the users and stakeholders of our systems. To assess this properly, it was critical to either observe the real users working with the system or to sit down with them and experience their pain, frustration, and sometimes: delight! Our team did this regularly by conducting evaluations, performing proficiency testing, and through coordinated multi-agency and stakeholder exercises under simulated public health emergency "war games".

Tying This All Back to Agile

While I've written more extensively on Agile in other posts on this blog, this post has not been about the "mechanics" of agile so much as it has been about the why. But, I want to look at just the first principle of the Agile Manifesto and make a brief comment:

Our highest priority is to satisfy the customer
through early and continuous delivery
of valuable software.

One might look at this principle and ask how can this be done when facing the situation I originally faced that featured my own client asking not for a continuous delivery model, but a "big bang" model? That's a very good question, and it's not one that has any quick-fix answer. My best advice here is that you need to learn the language and goals of both your client and your client's ultimate customers. If your client values financial returns, then ask him or her exactly what it is that generates financial returns. 

In my client's case, returns come in when more people purchase items through his system. The next question should be: what is the shortest path we can take to increase that rate? If the client answers that the shortest path is to rewrite the entire system and deploy a big-bang upgrade, then you're going to have to keep breaking that down into smaller and smaller value-added chunks. You might have to suggest straw-men in terms of business-value if your client will not prioritize by business value naturally. Ultimately, like in this story, reality may bear down on the situation and if you have done your best to incrementally develop the system in terms of business value, then you can deliver value, upholding your end of the deal to the utmost of your ability within your realm of control. Sometimes that's the best you can do, until you run your own show!

Wednesday, March 16, 2011

Thoughts on www.MVCConf.com : Excellent

I started listening to some of the videos at http://www.MVCConf.com today, including Scott Guthrie's keynote and Glen Block's lecture about WCF's super-enhanced REST support. Glen now calls himself a "REST head". Great!


The development of NuGet and Openwrap is really welcome to me. What must be 14 to 15 years ago now, when I started using PERL, I was very impressed by how well-oiled the machinery of CPAN was for installing packages and modules from the command line, even under Windows. When I started developing C# applications in 2001, I was very disappointed by the lack of a cohesive community of open-source packages available for Microsoft .NET. There have long been open-source projects. But, a package is different from a project. A package is shippable, deployable, consumable. I'm really happy to see this kind of thing coming into the .NET world.

I don't know where the credit goes, I'm sure it goes to many people. But, I definitely think a lot goes to Scott Guthrie for the enhanced openness that Microsoft has demonstrated in past years. I know from reading that this story also ties to Shawn Walker, the creator of DotNetNuke for his advanced forays into open-source based upon .NET.

Yes, I know the "entire stack" is not open-source, and that doesn't bother me that much.

Sunday, September 5, 2010

Aligning Business Requirements With Test-Driven-Development: Behavior-Driven-Development

Test-Driven-Development (TDD) is a topic that has become ubiquitous within software development over the past ten years or so. What is somewhat lesser known at this point is a particular evolution of TDD into what Dan North and Dave Astels have dubbed Behavior-Driven-Development (BDD). There are some specific problems with TDD that Dan and Dave have sought to correct by attempting to popularize BDD. This article will discuss some of the problems as well as some of the remedies.
 
While the stated goals of both TDD and BDD are similar, there are thought-process differences that should be understood by both technical developers and business people, including business analysts, project managers, product owners, and even CEOs. While one can philosophically argue that TDD “done right” is simply BDD anyway, I’ll trust North and Astels when they confidently state that the language people use is powerful and important and that is why they prefer to practice and speak of BDD now after years of experience.
 

Article Goal: Explain Why Businesses and Developers Might Want to Try BDD


This article will explain the distinctions between TDD and BDD and will show how using the BDD approach, as designed, should lead to:
  • Reduced costs due to higher fidelity specifications and communications
  • Reduced timelines due to less requirements churn and closer business and development alignment
  • Increased productivity due to the executable nature of BDD specifications

Test-Driven-Development

As a working definition of Test-Driven-Development from http://en.wikipedia.org/wiki/Test-driven_development is:

“Test-Driven-Development (TDD) is a software development process that relies on the repetition of a very short development cycle: first the developer writes a failing automated test case that defines a desired improvement or new function, then produces code to pass that test and finally refactors the new code to acceptable standards. Kent Beck, who is credited with having developed or 'rediscovered' the technique, stated in 2003 that TDD encourages simple designs and inspires confidence.

Test-driven development is related to the test-first programming concepts of extreme programming, begun in 1999,[2] but more recently has created more general interest in its own right.”

Scott Ambler also provides a great summary here: http://www.agiledata.org/essays/tdd.html.

Test-Driven-Development Workflow Diagram

The mantra of Red, Green, Refactor is well-known by developers. It looks like this:

image

Why and When To Practice Test-Driven-Development

It’s important to look at the complete historical, and current context, of Test-Driven-Development to understand its most-appropriate, and less appropriate usage.

Kent Beck, mentioned above as the most prominent formalizer of the practice, states this in his blog post “Where, Oh Where to Test?” at http://www.threeriversinstitute.org/WhereToTest.html:

“Cost, Stability, Reliability
On reflection, I realized that level of abstraction was only a coincidental factor in deciding where to test. I identified three factors which influence where to write tests, factors which sometimes line up with level of abstraction, but sometimes not. These factors are cost, stability, and reliability.

Cost is an important determiner of where to test, because tests are not essential to delivering value. The customer wants the system to run, now and after changes, and if I could achieve that without writing a single test they wouldn't mind a bit. The testing strategy that delivers the needed confidence at the least cost should win.

Cost is measured both by the developer time required to write the tests and the time to execute them (which also boils down to developer time). Effective software design can reduce the cost of writing the tests by minimizing the surface area of the system. However, setting up a test of a whole system is likely to take longer than setting up a test of a single object, both in terms of developer time and CPU time.”

More recently, he clarified the historical context of TDD with his post “To Test or Not to Test? That’s a Good Question”: http://www.threeriversinstitute.org/blog/?p=187

“Turns out the eternal verities of software development are neither eternal nor verities. I’m speaking in this case of the role of tests.

Once upon a time tests were seen as someone else’s job (speaking from a programmer’s perspective). Along came XP and said no, tests are everybody’s job, continuously. Then a cult of dogmatism sprang up around testing–if you can conceivably write a test you must.

By insisting that I always write tests I learned that I can test pretty much anything given enough time. I learned that tests can be incredibly valuable technically, psychologically, socially, and economically. However, until recently there was an underlying assumption to my strategy that I wasn’t really clear about.”

In this post, Kent goes on to state this about a product he developed called JUnit Max:

“When I started JUnit Max it slowly dawned on me that the rules had changed. The killer question was (is), “What features will attract paying customers?” By definition this is an unanswered question. If JUnit (or any other free-as-in-beer package) implements a feature, no one will pay for it in Max.

Success in JUnit Max is defined by bootstrap revenue: more paying users, more revenue per users, and/or a higher viral coefficient. Since, per definition, the means to achieve success are unknown, what maximizes the chance for success is trying lots of experiments and incorporating feedback from actual use and adoption.”

He later continues:

“When I started Max I didn’t have any automated tests for the first month. I did all of my testing manually. After I got the first few subscribers I went back and wrote tests for the existing functionality. Again, I think this sequence maximized the number of validated experiments I could perform per unit time. With little or no code, no tests let me start faster (the first test I wrote took me almost a week). Once the first bit of code was proved valuable (in the sense that a few of my friends would pay for it), tests let me experiment quickly with that code with confidence.

Whether or not to write automated tests requires balancing a range of factors. Even in Max I write a fair number of tests. If I can think of a cheap way to write a test, I develop every feature acceptance-test-first. Especially if I am not sure how to implement the feature, writing a test gives me good ideas. When working on Max, the question of whether or not to write a test boils down to whether a test helps me validate more experiments per unit time. It does, I write it. If not, damn the torpedoes. I am trying to maximize the chance that I’ll achieve wheels-up revenue for Max. The reasoning around design investment is similarly complicated, but again that’s the topic for a future post.

Some day Max will be a long game project, with a clear scope and sustainable revenue. Maintaining flexibility while simultaneously reducing costs will take over as goals. Days invested in one test will pay off. Until then, I need to remember to play the short game.”

Analysis of Kent Beck’s Cost-Benefit Based Strategy

If you read Kent’s posts carefully you will see that he made careful cost-benefit analyses whenever he decided to use or not use a TDD approach. When he developed JUnit Max, he chose to get the product features to the market as soon as he could, and then once he had an idea what customers wanted, he stabilized many of those features with tests.

So, what motivated Kent was a practical, reasonable, and important concern: financial viability and return-on-investment.

I thik it’s very important to be fully aware of these factors when deciding when and where to use TDD in any project. One of the main drivers of agile or Lean thinking is to optimize the whole, not necessarily individual parts all at once. Because of this, one must think about the larger context of a project.

Financial Investment Necessitates a Nuanced Approach to Development Practices

When thinking about the larger context, it’s easy for a developer to say something like: “We need this code to be well-factored, test-driven, and easy to maintain.” While this absolutely should be the goal of a developer, developers must also be cognizant of the larger context. Almost always, that larger context is that there is a financial investment in the project and the project’s success.  And, overwhelmingly more often than not, there is a specific timeline involved. Thus, it cannot ever be solely the developer’s responsibility to set the acceptance criteria for a system’s completion or its acceptable level of quality. Developers and project managers must present risks and tradeoffs to business stakeholders and collaborate to deliver value that is sufficient and as risk-averse as is necessary to the business stakeholders.

Finding the Correct Balance Takes Careful Thought and Collaboration

I cannot give specific recommendations in this article about any particular situation. Rather, I would recommend that all risks and tradeoffs be written down, categorized, and reviewed with key stakeholders in an open and honest fashion. If a product owner would favor a simpler, less glitzy UI in favor of core, sound, well-tested and stable backend services, then the team must focus on delivering this. On the other hand, if a product owner says that customers will be turned off by a UI that is vapid and barren, then the team must work hard to achieve that.

Building the correct features of any system is, as Kent Beck mentions, a very experimental process when the goal is not known. Because of this, it’s important to use practices that help in driving toward the correct features in the quickest fashion. Sometimes that approach is careful, stict adherence to TDD. Sometimes it is not. It takes judgement and careful balancing of all factors between business people and technical people to make the correct decisions.

Problems That Teams Can Face When Practicing TDD

In my experience, projects can get into trouble when project leaders do not make these nuanced decisions about TDD that require careful understanding, analysis, and collaboration amongst the entire team. In a project without a schedule, then it might make sense to practice a strict form of TDD. In projects that have specific dates set in stone, a team must make decisions about when and where to apply strict TDD and when and where to accept technical debt in order to meet those dates.

Delivering Business Value and Mitigating Project Risk Through Behavior-Driven-DevelSopment

It might come as no surprise by the title of this article, that others much more learned in these practices and problems than I have sought remedies. Namely, Dan North and Dave Astels have written and presented widely on Behavior-Driven-Development (BDD) and its close aligntment to business success criteria. The rest of this article will introduce BDD and provide links to sites, videos, presentations, and a sample project in .NET by Rajesh Pillali that provide extensive information.

Introducing Behavior-Driven-Development

As stated on http://behavior-driven.org, the definition of BDD is:

“Behaviour-Driven Development (BDD) is an evolution in the thinking behind Test-Driven-Development and Acceptance-Test-Driven-Planning.

It brings together strands from Test-Driven-Development and Domain-Driven-Design into an integrated whole, making the relationship between these two powerful approaches to software development more evident.

It aims to help focus development on the delivery of prioritised, verifiable business value by providing a common vocabulary (also referred to as a Ubiquitous Language) that spans the divide between Business and Technology.”

Dan North’s original formulation of BDD is here: http://blog.dannorth.net/introducing-bdd/. Dave Astels clearly explains it more succinctly in his own article here: http://techblog.daveastels.com/files/BDD_Intro.pdf

Business Analysts Write Executable Specifications When Teams Practice Behavior Driven Development

Here is an example BDD feature specification from the SpecFlow project’s web site:

image

There are other “Steps” in the worflow, but here is how the ultimate fulfillment of that specification gets executed and measured:

image

TODO:

Complete article

Complete Examples

Rajesh Pillali provides an excellent article on CodeProject here: http://www.codeproject.com/KB/architecture/BddWithSpecFlow.aspx

Saturday, September 4, 2010

Retrospective of Greg Young’s Final CQRS and DDD Online Course

I woke up at 4 am so that I could virtually attend via LiveMeeting Greg Young’s final online CQRS and DDD course. While I had some sound issues and had to keep coming back into the session, I can still say: Wow! Greg’s knowledge is excellent and his presentation was great.

You can watch him deliver a similar talk at this Skillsmatter podcast about the business perspectives of this architecture: http://skillsmatter.com/podcast/open-source-dot-net/greg-young-cqrs-event-sourcing-the-business-perspecive

It’s easiest these days for me to learn visually, so in review, here are a couple of slides from another blogger, Dylan Smyth, who blogged about this that summarize the distinction between a CQRS style architecture and a more typical stack:

image

 

 

 

 

 

 

 

 

Rinat Abdullin has a great diagram on his own blog depicting what Greg also calls the Task-Driven UI:

image

 

To summarize in my own, short, words:

Typical Architecture

On the left side we have the “typical” architecture which has this kind of interaction model:

  1. User clicks a button in a client.
  2. Client issues a request to the server, asking for Product with ID 50, for example.
  3. Server fetches an entity for Product with ID 50.
  4. Server creates a DTO from this entity and sends it to the client.
  5. The client modifies this DTO.
  6. Client ships the modified DTO back to the server for an update.

CQRS Architecture

He contrasts that the right side, which he says may appear at first to be more complex, but it actually turns out to be simpler and less costly because of the Thin Read Layer in which the operations are optimized for read, not write. This means the translation from data to DTO occurs directly here.

  1. User clicks a button in a client.
  2. Client issues a read request to the server, asking for Product with ID 50.
  3. Server fetches the data for Product with ID 50.
  4. Server creates a DTO from this entity and sends it to the client.
  5. The client operates on a screen and issues a Command to the server, which is not equivalent with sending a modified DTO back to the server.

An important note here is that the "Event Store” is where the commands are serialized, which does not have to be in a relational database. The De-Normalized Data Cache is where a “view” of data created and stored as a result of the Events being stored.

CQRS Diagram

This is an image that Udi Dahan uses to describe CQRS in his own post Clarified CQRS:

image

Domain-Driven-DESIGN

He also discussed Domain-Driven-Design after talking about CQRS, but unfortunately I did not hear all of that.

Recommend Resources

In addition to the Skillsmatter podcast above, here are some other recommended links about CQRS:

  1. Super Simple CQRS Example from Greg Young: http://codebetter.com/blogs/gregyoung/archive/2010/08/31/super-simple-cqrs-example.aspx
  2. Clarified CQRS, Udi Dahan: http://www.udidahan.com/2009/12/09/clarified-cqrs/
  3. Udi Dahan on CQRS, DDD, and NServiceBus: http://www.infoq.com/interviews/dahan-cqrs-ddd-nservicebus
  4. Command-Query Responsibility Segregation, interview with Udi Dahan: http://www.infoq.com/presentations/Command-Query-Responsibility-Segregation
  5. Greg Young Discusses State Transitions in Domain-Driven Design and DDD Best Practices: http://www.infoq.com/interviews/greg-young-ddd