Profile picture
Michael D. Hill @GeePawHill
, 34 tweets, 5 min read Read on Twitter
software -- programs -- can be understood as (potentially huge) orchestras playing in concert.
depending on your level of abstraction, you might imagine systems, subsystems, layers, packages, objects, or even functions as the individual players.
(aside: folks often make major distinctions in these abstractions, but to my touch, they feel all the same thing, just with ever larger labels on ever subsets. and at bottom, 100% of it is von neumann architecture code.)
for the purposes of this conversation, i'll be thinking and using classes and objects, as that's the main level at which daily geekery is conducted in the modern synthesis. but remember, the players could be any of these.
the players *collaborate* to perform their function. they are collaborators. we often speak of roles or responsibilities -- sometimes very formally -- and that language is pointing at the same thing. parts of programs work together. they collaborate.
i pretty much always use TDD for anything bigger than the very rare "three hours, ship it, never look at it again" thing. i won't rehearse the reasons for this, but just offer my official view: it lets me ship more value faster when i work that way.
anyway, when TDD'ing, all collaborators are decidedly not created equal, and they're unequal in a peculiar way. let me throw a strange pair of terms at you: "graceful" and "awkward".
it's not an all-or-none thing, but one of continuum, with some collaborators being very graceful and some being very awkward, and plenty in between, and some awkward sometimes and not others.
TDD works for me because the tests are cheap. we've used this word before, and i used the phrase "easy to". easy to write, to read, to scan, to run, to change, to collect, to debug.
the idea is really important, cheapness, for a very straightforward and human reason: when things aren't cheap, we don't do as much of them. if the things have substantial extrinsic value, not doing as much of them is A Bad Thing[tm].
when i'm adding new functionality, my new stuff is usually merrily collaborating away, with my code, her code, library code, framework code, etc. etc.
a *graceful* collaborator is one that makes or keeps my testing of the new functionality cheap. an *awkward* collaborator is one that prevents my testing from being cheap. (remember as we go, continuum not binary value.)
the archetypal graceful collaborator in most modern OO languages is the string class. many TDD'ers write their very first tests on code that manipulates strings. and the tests are chock-a-block with assertions that two strings do or don't match.
awkward collaborators aren't always the same from one programming environment to another. in java, the simplest awkward is usually the File class. in other worlds it might be different.
a sampling of common awkwards: a ticks-since-1970 clock. a physical file, a relational database. fronts for external devices, like screens or printers. fronts for other complex programs, servers or report-writers.
what makes graceful graceful and awkward awkward? well. anything that makes me not want to use a test to validate that my code does what i meant it to contributes to awkwardness. and graceful is the absence of any of those things.
awkwardness can be in runtime, it can be in setup cost, it can be in difficulty obtaining the output data, it can be almost anywhere. in our material at Industrial Logic (cites at end), we just say "if it makes you not want to test it, call it awkward and do something about it."
strings are relatively graceful, because they require one-liner setup, one-liner probe, they have no externalities, they run fast, and for all but the noobs, their API is incredibly well-understood.
(note: don't make the mistake of thinking that this is because strings are simple or have no dependencies. try learning every single corner of, say, c++ std::string. pro-tip: bring food, as you won't be done before lunch -- next week.)
a substantial part of doing TDD in the real-world hinges on this awkward/graceful distinction. in fact, the reason so many toy TDD exercises are in fact toys is because they include few or no awkwards, where real-world TDD is replete with them.
how one handles awkward collaboration --
potential and pre-made, is at the heart of successfully using TDD to ship more value faster.
there are several different ways to address awkward collaboration, and no single one ring to rule all awkwards. about all i can do is offer some generic advice, for the moment.
1) we struggle mightily to keep the current class -- the new functionality -- from becoming the newest awkward collaborator in our collection.
2) we can very often divide the work our code does into an awkward part and a graceful part. sometimes that's as easy as splitting one method into two. the first method turns awkward into graceful, the second method takes graceful.
3) we nearly always use interfaces when an implementation is inherently awkward. big girls and boys supply a graceful (if usually incomplete or simplified) variant of an awkward FOR NO OTHER REASON than to keep from passing on the pain.
4) alternate constructors -- one taking an awkward, one taking a graceful, are extremely common.
5) indirection is your friend in that 95% of your job that has almost no impact on program performance.
6) the most important part of your code is usually *not* the bringing together of the data, but the processing of it. if we intermngle those modes, we often create permanent awkwardness.
7) often, the many paths through my code all have a prolog or epilog that's awkward, with pure grace in the middle. if i tie those into the code in a non-separable way, i'm locking everyone into my awkwardness for all time.
8) the smaller an awkward's interface, the cheaper it is to fake. (faking has lots of names, most commonly mocking, a misuse of that term's origin & intent. it is making an artificial "test only" graceful from some inherently awkward thing.
anyway, it's getting on toward bedtime, and that list is weird and disjoint, so i'm going to leave it for now.
maybe just start here: learn to recognize the feeling that you don't want to roll a test because it's not cheap enough to do so. think about what could be changed -- your code or others -- that might ease that pain.
here's your blog: "Awkward & Graceful Collaborators: A Key Distinction In TDD"
geepawhill.org/awkward-gracef…
(proof of bedtime: i screwed up the embedding on this blog post. think i got it now.)
Missing some Tweet in this thread?
You can try to force a refresh.

Like this thread? Get email updates or save it to PDF!

Subscribe to Michael D. Hill
Profile picture

Get real-time email alerts when new unrolls are available from this author!

This content may be removed anytime!

Twitter may remove this content at anytime, convert it as a PDF, save and print for later use!

Try unrolling a thread yourself!

how to unroll video

1) Follow Thread Reader App on Twitter so you can easily mention us!

2) Go to a Twitter thread (series of Tweets by the same owner) and mention us with a keyword "unroll" @threadreaderapp unroll

You can practice here first or read more on our help page!

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just three indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member and get exclusive features!

Premium member ($3.00/month or $30.00/year)

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!