InfoQ

Interview

Coplien and Martin Debate TDD, CDD and Professionalism

Interview with Jim Coplien and Bob Martin by Floyd Marinescu on Feb 18, 2008 05:56 AM

Community
Agile
Topics
Delivering Quality,
Unit Testing,
Agile Techniques
Tags
Criticism,
XP,
TDD,
Testing,
CDD,
Antipatterns,
Refactoring,
Contract First Development
Summary
Debate sprang up at JAOO '07 around Bob Martin's assertion that "nowadays it is irresponsible for a developer to ship a line of code he has not executed in a unit test." In this InfoQ video, he debated with Jim Coplien on this and other topics, including Design by Contract vs. TDD and how much up-front architecture is needed to keep a system consistent with the business domain model.

Bio
Bob Martin is an Agile Manifesto author, and author of books on Agile Programming, XP, UML, O-O Programming, and C++. He is CEO and president of Object Mentor www.objectmentor.com/ Jim Coplien is a software pioneer in o-o programming and C++ and multi-paradigm design. He appreciates the human side of design, and has written critically acclaimed books on design and development.
Introduction by Floyd Marinescu
Bob Martin: First thing I need to say is: I am sitting here next to one of my heroes. I read Jim's book in 1991-1992, changed the way I thought about software, changed the way I thought about C++ in particular, so it's a great honor for me to be here. I think we have a disagreement - I'm not sure, possibly, it may a difference in perspective - but my thesis is that it has become infeasible, in light of what's happened over the last 6 years, for a software developer to consider himself "professional" if he does not practice test driven development.
Bob Introduces his 3 laws of TDD and Jim Responds
Alright. But you do not accept the thesis that the practice of test driven development is a pure requisite to professional behavior in 2007.
OK. So we can come back to that one because I think that is an interesting topic, just on the topic of professionalism, but before we do that: there has been a feeling in the Agile community since about '99 that architecture is irrelevant, we don't need to do architecture, all we need to do is write a lots of tests and do lots of stories and do quick iterations and the code will assemble itself magically, and this has always been horse shit. I even think most of the original Agile proponents would agree that was a silliness. I think if you went and talked to Kent now he would be talking about what he always talked about: metaphor, whatever the heck that was.
Sure. OK. But now let me come back and throw a different light on this. I think architecture is very important, I've written lots of articles and books about architecture, I am the big architecture freak. On the other hand I don't believe architecture is formed out of whole cloth. I believe that you assemble it one bit at a time, by using good design skills, by using good architectural skills, over the weeks and months of many iterations. And I think that some of the architectural elements that you create, you will destroy; you will experiment in a few iterations with different forms of architecture. Within 2 or 3 iterations you will have settled into the architecture you think is right and then be entering into a phase of tuning. So my view of that is that the architecture evolves, it is informed by code that executes, and it is informed by the tests that you write.
So I would say that a little differently, and take exception to some of it. I would not very likely fill in the interfaces with abstract member functions or defunct member functions. I might create objects that will fill the place of interfaces. So, in Java terms, I might have an "interface-something" with nothing in it, but I am not going to load it with a lot of methods that I think might be implemented one day. That is something that I am going to let my tests drive, the requirements drive, and I am going to be watching it like a hawk to see if there is any kind of architectural friction that would cause me to split that interface.
OK. And I would even agree with that. You need something there to give the object meaning. I am going to be really minimal about that.
And then I am going to let executing code inform my future decisions, so I am not going to create a massive architecture, or a huge system based on speculation.
So back to the beginning: how long would you spend before you started writing executable code. Let's say, on a system that will eventually wind up being two million lines of code?
Would you have tests, testing those wirings?
Excellent. So where is our disagreement? Perhaps our disagreement is on the notion of TDD and professionalism. That was the second part.
They practice TDD? (smiling)
Yeah, I know, and I am going to push on that one, because I think that something our industry has lacked is a standard of professionalism.
But that is not actually my definition, I was joking. I think that nowadays it is irresponsible for a developer to ship a line of code that he has not executed in a unit test, and one of the best ways to make sure that you have not shipped a line of code that you have not tested is to practice TDD.
So I am having trouble with that. As I remember Eiffel - and I actually thought this discussion was put to bed a long time ago - as I remember Eiffel and "design by contract," you specify preconditions, post conditions and invariants around every method and around your class, the invariants of your class. Test driven development, or a suite of unit tests, virtually does the same thing, it specifies a set of incoming checks on the arguments, outgoing checks on the returned values, explores the state space, as you said, of the methods. So I always thought that they were one-to-one, you could always transform contracts into unit test or transformunit tests into contracts, with the exception that the direction of the dependencies is different, and you know that I am a big dependency freak. Unit tests depend on code, on production code, which I think is good, production code doesn't depend on unit tests; whereas contracts are smeared through the code, which bothers me.
I am surprised that you think the code mass is different.
I agree with that: there are messy tests, but there is messy code. I don't like arguments that the "tool is easy to abuse therefore you shouldn't use it," that would invalidate almost everything...
Well, OK. And do you see contracts being abused in broad practice?
Right! By the way, since we've just got a couple of minutes left, just a trivia question - and I don't know the answer. Who is it that first used "DD" with some letter in front of it? We've got CDD now, we've got BDD, TDD and I don't know what else and the earliest one I can remember is Rebecca Wirfs-Brock, Responsibility Driven Design. Was there an earlier one?
show all  show all

Related Sponsor

VersionOne is recognized by Agile practitioners as the leader in Agile project management tools. Companies such as Adobe, BBC, CNN, Dow, HP, IBM, Sony and 3M have turned to VersionOne to help deliver greater value to their customers.

10 comments

Reply

Are we Growing or Building Systems? by Juan Bernabo Posted Feb 18, 2008 3:13 PM
Re: Are we Growing or Building Systems? by Henri Frilund Posted Feb 19, 2008 2:08 PM
DbC an aspect of TDD by Michael Sawicky Posted Feb 19, 2008 9:23 PM
Growing vs Building, Bottom up vs Top down by Paul Beckford Posted Feb 24, 2008 2:08 AM
More on the TDD Controversy by Martin Jul Posted Feb 26, 2008 7:47 AM
Fantastic by Stuart Charlton Posted Feb 26, 2008 9:51 AM
Cedric Beust weighs in on Test-First, -Last, etc. by Deborah Hartmann Posted Mar 2, 2008 2:43 PM
Cause and effect by Gordon Reynolds Posted Mar 4, 2008 11:58 AM
CDD vs. TDD by Tim Stewart Posted Mar 5, 2008 5:52 PM
Re: CDD vs. TDD by Johannes Brodwall Posted Apr 5, 2008 5:12 PM
  1. Back to top

    Are we Growing or Building Systems?

    Feb 18, 2008 3:13 PM by Juan Bernabo

    Hi, I just wanted to say that I´m a fan of both guys, I´m also an architecture freak that is learning to try to let it go, and do architectural decisions to be made in a more just in time way. When Jim talks about TDD he talks about his assumption on TDD as testing units like in isolation not connected with business value, but pretty much TDD is evolving to include and start with the tests that drive an user story, pretty much like an executable specification, and not as just a unit test of a class in isolation, but exercising all the architecture by each functional test that specifies a user scenery. I think the bottom of this discussion is what is the right approach build or grow a system? And if we grow it, can we refactor the architecture as nature does when a tree grows from a seed to it´s final form? Why nature goes refactoring things, could it simply go trying to build trees instead of growing them? Christopher Alexander in his "The Nature of Order" collection talks about a process for architecture were they are generated and not searched, he even gets to say that alive or valid configurations were mathematically not possible to get by searching the configuration space, so the ONLY way to have systems that are healthy requires a generative approach. So he talks about two processes of creating an architecture, by search, something done upfront, and something done by generation, what he calls whole extension transformations, pretty much what I think is TDD, the only trouble with this is that the next transformation must be decided by us just in time "by evaluating the level of life that particular part of the system has", this is made by looking into ourselves and feel if that make us feel more alive as more beauty in it. I think this skill is not teached, and most of the great developers and architects that I know, they can tell, or evaluate this just by looking at code and say this "sucks" or this is beautyfull, but most developers don't use this information to guide their design decisions, and that maybe is getting us into trouble with TDD. Today technologies allows us to do architecture agnostic code, by using late wiring and IoC, so much more easily than 10 or 15 years ago we can effectively delay the decision about how to wire things even as late as in runtime. This allows me to be free on some of the decisions about architecture, maybe this were architectural decisions already made. So maybe Agile as in other disciplines is getting us to rethink our assumptions or methafors about all disciplines and we got to architecture. Probably architects should work in code driven by most important or architecture significant user stories or use cases to implement them and evolve architecture in a test driven way to evolve and stabilize them before they can talk about a settled architecture and look continuously for opportunities. Juan.

  2. Back to top

    Re: Are we Growing or Building Systems?

    Feb 19, 2008 2:08 PM by Henri Frilund

    I like gardening and I think there's some analogy in gardening to making software systems :) To get tomatoes from your own garden, you can't really build them. But it doesn't work that well if you just throw tomato seeds everywhere and start waiting either. Well yes, you might eventually get a tomato strand that will grow by itself, but it'll take a long time and you'll probably get really small tomatoes. So what I do when I want big tomatoes fast is I build an environment upfront that makes it possible for my tomatoes to grow fast and after that I nurture them by giving water etc. I think this principle applies for software making quite well because you really don't usually have the time to wait for the architecture to "grow" naturally so you set up an environment (domain model, main contracts, architectural borders etc) and then start "growing" the system using TDD or WhateverDD. This applies especially if the underlying domain is established (which it usually is). -Henri

  3. Back to top

    DbC an aspect of TDD

    Feb 19, 2008 9:23 PM by Michael Sawicky

    It is great to see these topics come into broader conversation; thank you! These days I am more and more surprised that we continue to frame Design by Contract and TDD unit testing as “doing virtually the same thing.” These practices are complementary, not exclusive of one another. The unit testing aspect of TDD provides specification-context that informs design and helps us control the increments of our design/development cycle. DbC on the other hand is a concise way to inspect and enforce design detail – using a mechanism that is more concise and efficient than external unit tests. Although it’s true that unit tests can be used to do what DbC does, it can be a lot more work to do so. DbC also provides value beyond the context of unit testing since assertions continue to be exercised during system testing and functional testing. Actually, when given a robust implementation, assertions can also be available for analyzing faults in production systems. Perhaps it would be helpful to describe DbC as an *aspect* of TDD, with the best “TDD value” being achieved when both unit testing and DbC are combined. Who knows, maybe having the discipline to use both practices together is a sign of a “highly evolved” professional? ;-) Thanks again for covering these interesting topics! -MSaw

  4. Back to top

    Growing vs Building, Bottom up vs Top down

    Feb 24, 2008 2:08 AM by Paul Beckford

    Firstly great article. This type of stuff is the meat of what programming is all about and more articles like this would be welcomed. Thanks InfoQ. Bob and Jim have highlighted the issues as have most of the posters. I think it isn't either/or and that you need to do both. Where XP stepped in is it re-addressed the balance after years of focusing on top down methodologies like Booch, OMT, RUP etc. The truth is you often need very little top down design/architecture and that design should be validated through real stories and bottom up (TDD) code. I've heard this called producing a "walking skeleton" in the earlier iterations that provides a first pass architecture and provides a framework to hang other stories on TDD style. From what Jim has said, it sounds as though he does something similar. I never really understood Kent Becks Metaphor idea much, but an architectural "skeleton" is an easier idea to grasp and can serve the same purpose by communicating the "design in the large" to the entire team. To me the power of validating top down decisions (architecture) with bottom up code (TDD), is that you will get signs that your architecture doesn't fit your problem, very early on. These will manifest themselves as "architectural smells", and these smells provide an opportunity to evolve your architecture to something better (often simpler) at very low cost, since you haven't made a huge commitment (deferred commitment). Couple of points that haven't been raised yet: 1) Domain Driven Design (DDD) plays well with TDD/BDD. Your "ubiquitous domain language" and high level domain model is often the starting place for your top down architecture/design, again validated bottom up. 2) Ron Jefferies website is a great place to learn how to do TDD right from an expert. TDD provides opportunities for learning an discovery by "listening to your code". This "listening" is a skill and goes way beyond any hard and fast rules. To develop skill in anything takes time and practice: http://www.xprogramming.com/ Ron discusses these issues also, and explores them through "experiments in code". He calls what Jim calls "architecture" "programming by intent". Which is a name I like because it stresses the fact that you think you know what your code should do. After doing TDD for a number of years I am still surprised by just how often my intent is actually sub optimal or just plain wrong. Paul.

  5. Back to top

    More on the TDD Controversy

    Feb 26, 2008 7:47 AM by Martin Jul

    TDD will ruin your architecture! When Jim Coplien said this in his presentation about Scrum and Architecture at the JAOO 2007 conference he really got people's attention. His statement sparked one of the most passionate debates at the conference. I posted a summary of the discussion on our blog here: The TDD Controversy.

  6. Back to top

    Fantastic

    Feb 26, 2008 9:51 AM by Stuart Charlton

    Two of my heroes! Jim's points should be remembered: Good architecture requires "stable intermediate forms" to evolve: structure matters! Secondly, you can't create an structure without denoting what it means to some degree. But as Bob says, just don't go too crazy with it. As for the 'professionalism' angle, I'm concerned this is rather harsh. I fear that it's true, though. The vast majority of software developers in my experience across multiple industries don't practice TDD, or if they do, they only make a token effort of it. Does that make them unprofessional? Perhaps. I'm not sure what good would come out of pointing it out. If you want to change the behaviour of the industry, start with providing incentives to IT hiring managers and project managers whose mindsets lead to dysfunctional behaviour in their projects. Calling their teams "unprofessional" might scare them into action, or it might just make them defensive ("we don't need the best, just what we can get" is one line I've heard numerous times.)

  7. Back to top

    Cedric Beust weighs in on Test-First, -Last, etc.

    Mar 2, 2008 2:43 PM by Deborah Hartmann

    I noticed that in our recent video on Design for Testability, Cedric Beust raised the topic of TDD, calling it "the elephant in the room." He asked those who don't write all their tests up front:

    Don't you feel a bit dirty? What with all those books ... telling you you should be doing TDD, and otherwise you are not professional? Is it just me? I try to do it... sometimes it feels right, sometimes it doesn't..." ... am I doing something wrong, or is it ok?

    Of his own work on TestNG he notes that, although he does value TDD he actually seems to write only 10% of his tests up front, and he went on to look at some of his concerns with TDD. You can view this part of the talk around 32 minutes into the presentation.

  8. Back to top

    Cause and effect

    Mar 4, 2008 11:58 AM by Gordon Reynolds

    I'll start by admitting I haven't yet watched this debate, so I'm really just reflecting on the statements I see in other replies to this thread, e.g., that TDD/GUT = professionalism. I have been trying - in vain - for months, if not years, now to introduce a unit testing "ethic" in the team I work with. Easily the most common "reason" given is that there "just isn't time". But I detect an undertone of skepticism that is really the root of the problem: the developers here just don't see any positive value in it. What I finally realized is that it is insufficient to simply state that (1) it's an industry best practice, that (2) the likes of Martin Fowler and Robert C. Martin are advocates of the practice, so (3) please unit test. All such arguments are bound to fail in one way or another without first discussing what objective you hope to achieve by adopting the practice - and by showing that what developers are doing now FAILS to achieve those objectives, e.g., fewer bugs, better design, refactoring freedom. Advocating a practice in the abstract is tantamount to saying "just do it because I say so". So, IMHO, professionalism is not defined by practices, it is defined by the objectives those practices hope to achieve, and the mindset of the developer who adopts them. After all, it is fairly easy to generate useless unit tests; does that make you a "professional"?

  9. Back to top

    CDD vs. TDD

    Mar 5, 2008 5:52 PM by Tim Stewart

    Contracts from CDD are passive in that a contract violation is caught while running the product. Someone or something still has to exercise the code to catch the contract violations. That something might be a unit test. If you choose to exercise the code manually, you have your work cut out for you as you try to exercise all of the branches. CDD by itself is not enough. You need people or other code to exercise the system. If you use people, you need to document the various interactions required to test all of the branches of the code. BTW, when a contract violation occurs, can you continue running the product or is some exception thrown? Also, when a contract is violated, you may have a hard time tracing down why the contract failed. TDD addresses this very nicely by having isolated, stateless tests. Tests from TDD are active in that they can be run automatically. When a test fails, subsequent tests can still be run. When a test fails, it's easier to find out why.

  10. Back to top

    Re: CDD vs. TDD

    Apr 5, 2008 5:12 PM by Johannes Brodwall

    I have also only seen "passive contracts". But Cope hints in this interview (and elsewhere) about teams using some sort of tooling to exercise the contracts. I would very much like to see these tools demonstrated. My second difficulty with CDD is the fact that many methods are coupled in some way. Even with the humble Stack.push, how do you write a sufficient contract that doesn't mess up the object state in the process? (If you consider an answer, remember both to check "Stack.top == argument" and "Stack.pop; Stack.top = @pre.top")

Exclusive Content

An Overview of the eXo Platform

Mestrallet and Grall cover the eXo platform, the Portlet 1.0 (JSR 168) and 2.0 (JSR 286) specs, eXo Web 2.0 Portal, JSR 286 Inter-portlet communication, eXo JCR and eXo Enterprise Content Management.

The Top 10 Ways to Botch Enterprise Java Application Scalability and Reliability

Purdy discusses Java scaling, performance vs scaling, rewriting frameworks, databases, bottlenecks, abstractions, disaster recovery, one-size-fits-all architecture, big JVM heaps and network failures.

Building Scalability and Achieving Performance: A Virtual Panel

Our panel of leading experts explores some of the challenges and thought processes that go into making their apps as scalable and performant as possible.

Domain-Driven Design in an Evolving Architecture

Mat Wall and Nik Silver explain how their has been using Domain-Driven Design in an evolving and Agile environment, at high traffic news site guardian.co.uk.

Avi Bryant on DabbleDB, Smalltalk and Persistence

In this interview, Avi Bryant talks about the Smalltalk web framework Seaside, DabbleDB, using Smalltalk images for persistence instead of an RDBMs, GemStone and more.

Book Review: Agile Adoption Patterns, A Roadmap to Organizational Success

With Agile adoption, context is everything: this book offers patterns and tools to help determine which practices most contribute to meeting your organization's goals.

Rob Windsor on WCF with REST, JSON and RSS

WCF is not just for SOAP based services and can be used with popular protocols like RSS, REST and JSON. Join Rob Windsor as he introduces WCF 3.5 and its new native support for non-SOAP services.

Christophe Coenraets Discusses Flex 3, AIR, and BlazeDS

Christophe Coenraets discusses Flex 3, Flex Builder, AIR, BlazeDS, Adobe and open source, integrating Flex with existing applications, and integrating RIAs with search engines and browsers.