alrighty-then. this hard-tdd vs soft-tdd thing.
a couple of days ago, i worked through some underplayed premises of TDD, here.
along the way, i touched on what i call hard TDD vs soft TDD.
the terms derive from AI, where proponents differ on soft-AI vs hard-AI. a semantic association, not a real analogy, so i’ll skip that. hard vs soft here isn’t about technique, it’s about what we believe the value of the technique includes.
and don’t be confused, there are (at least) three positions: no-TDD, soft-TDD, and hard-TDD. i am a hard-TDD man, myself.
the terms have to do with the value of TDD. most standard discussions of TDD as a process look at the results and offer the extrinsic value produced by them.
the tests are good because, variously, they’re progress pitons, they’re living documents, they’re validators, and so on. i believe all that, of course. hard-TDD certainly incorporates all of soft-TDD and none of no-TDD. but hard-TDD makes a very bold claim.
TDD designs are *better*, even if we deleted all the tests.
take 2 codebases, one produced w/TDD, one produced w/o. do not consider the tests themselves. hard-TDD predicts the w/ is better designed. this sounds mystical, and i’m sure to hear about that from those who (naturally, healthily) resent the dogmatic behavior of some TDD folks.
but it’s not mystical at all. i haven’t worked out all the links rigorously, but i’ve made a start, and i’ll sketch that out here.
consider the SOLID principles. you don’t have to be 100% sold to see that they clearly have merit as design forces, yes? after all, in many ways they’re restatements of 40 years of work defining and describing “good design”.
take a case like ISP, the interface segregation principle. this idea is about proper ‘jointing’ of problems when designing. it pushes us two directions at once, towards smaller classes with shorter API’s, and, along w/the SRP, towards tight self-contained APIs. SRP = single responsibility principle, the idea i used to call Just One Thing[tm].
so these principles strongly suggest we give grave consideration to how we break problems up, and that we attend closely to size. and here’s the thing. that is *exactly* what the practices of TDD drive us toward as well.
i should pause here. it’s clear to me that “my” TDD isn’t everyone’s.
the noobification of everything has spawned mantras & flowcharts galore. when i say TDD, i mean the loose catalog of moves i’ve been led to. they include precepts from CI, from TDD itself, from experience owwie and otherwise. the judgment premise should remind us all of that. i don’t have or teach a flowchart for my TDD in any simple format. i have a toolbelt with a lot of tools. i use my judgment constantly in applying them.
all that having been said, the closest phrase i have to describe what i do is in fact TDD. so i will stick with it. the world needs another X-driven-Y label like it needs more holes in its wobbly little head.
back on track, then. the ISP+SRP isn’t the only force that TDD leans us towards from the SOLID world. microtesting pushes me towards the DIP — dependency inversion principle, colloquially, don’t make imporant things depend on details.
when i’m microtesting to make some new class, i am constantly spawning collaborations and putting those in other classes. not from a sense of design purity, but from a sense of rich, raw, unmediated, overpowering, umm, laziness.
it works like this. i know X is gonna need parts that deal with Y. i don’t roll that work into X, i push it to Y. i do this because i am after X right now, the heart of X, the center of X. i’m not after the detail of the Y-parts.
think of it this way. i need to parse these lines. that’s the central job of the CharacterParser class. and CharacterParser does not care where the source lines come from. it doesn’t matter. that is unimportant. i don’t hesitate to name the Lines class (or in this case, use the modern line-oriented stuff built in to the JDK).
i give my CharacterParser a Lines object. parsing out d&d characters doesn’t depend on where that text comes from. the full solution depends on that. but the force of wanting to microtest the interesting part of CharacterParser leads me quickly to DIP.
and that’s it, for now, on my underlying reasoning for backing hard-TDD.
there are other variants on “what is a good design” than SOLID, some older, some newer, some in conflict. much has been made in recent years, partly via functional programming, of immutability & function composition, for instance.
as a TDD’ing microtester, i love immutability and i love composition. not because of the deep insights of design theory. because they are easier to microtest. immutability is nice because there’s no invisible state, my methods all return testable objects, and i never have to reach inside. function composition is nice because it makes it easy to satisfy myself that A works, B works, and + works, and thus that A+B works.
Hard-TDD, which is my current working stance, is that testable designs are better designs *intrinsically*, even w/o tests.
they’re better because the natural act of being a lazy TDD’er using microtests is to shape designs towards our best current grasp of “good”. that’s not a universal position. fortunately, the soft-TDD case is itself pretty compelling, and hard-TDD certainly embraces it.
thanks for tolerating. if you want to talk about any of this, just give me a ping. tip your waiters, they work hard.