In article <
fnj2ar...@mid.individual.net>,
Ian Collins <
ian-...@hotmail.com> wrote:
>On 04/06/18 01:26, Daniel wrote:
>> On Friday, June 1, 2018 at 11:00:51 PM UTC-4, Ian Collins wrote:
>>> On 02/06/18 14:17, Mr Flibble wrote:
>>>> I see Ian Collins is on his TDD high horse again. Fecking
>>>> clueless.
>>>
>>> Feel free to write code that you don't know works.
>>>
>> Are you suggesting that TDD is the one and only way to write code
>> that you know "works"?
>
>No.
>
>> Works in what sense?
>
>Works as in does what the detailed design (the tests) says it is
>supposed to do.
"Test as design" is an attempt to respond to the reality that a
detailed design document (in the waterfall sense) is destined to
become hopelessly out of date in very short order. But it does
not follow that this is the only way to document a "design", nor
that it is even a good way to do so (let alone sufficient for
long-term maintenance). Tests can certainly perform some
documentary function, but they fall far short of the sort of
design that may be required for non-trivial software.
The example was brought up of implementing IETF standards; in
that case, an RFC is sort of like a design document for a
protocol (yes, there are RFCs for other sorts of things, but
let's keep it simple). I hope we could all agree that if a
protocol were described by a series of tests, that would be a
poor way to communicate a description of the protocol sufficient
for an implementer; I would argue it would be so opaque as to be
insufficient.
>> Are you one of those
>> people that talk about "100 percent" test coverage?
>
>No, in software, there is always the unexpected. But I do strive to
>minimise the unexpected through test coverage.
Test coverage is neither necessary nor sufficient for minimizing
the unexpected. Unit tests are useful as an easy to use and
easy to understand communication medium for verifying that
software behaves in an expected way in the context of a highly
controlled testing environment, but of course there are other
ways to do that. However, often those ways aren't easy to use
without special training; testing provides a nice balance as a
platform for shaking a lot of bugs out of the tree. This is
presumably why it is so popular.
However, it is manifestly insufficient: suppose I have a bit of
code that is succeptible to perturbations of various kinds in
the execution environment: for example, it may be subject to
tight timing guarantees. How does one probe that in the context
of a unit test? Or perhaps I need some guarantee of time
complexity for an algorithm as applied to some user-provided
data. Unit testing is awkward at best for this purpose.
>> Do you write
>> tests for all your accessors, the way Robert Martin and Kent Beck do
>> in their books?
>
>Trivial accessors, no and neither to they.
>
>> Do you think that is the best use of your time for
>> keeping your software free of defects?
>
>Yes because it helps me write code faster and better. Maybe not
>initially, but the time saved in chasing down bugs, retesting after
>changes or stepping through code in a debugger pays off pretty quickly.
>Tests are an investment in the future of the code.
This conflates the utility of a robust body of unit tests with
the practice of TDD. The former is undeniably useful; but the
latter is only useful as a means to the former and it is
trivially not the only such means.
>> A few points.
>>
>> One, for a non-trivial specification, it would presumably take an
>> arbitrarily large number of tests, in some cases an infinite number,
>> to cover off all outcomes. Since nobody has that much time, we
>> sample, sometimes randomly, sometimes deterministically, e.g. edge
>> cases. It's nonsensical to talk about "100" percent coverage unless
>> you're talking about software verified through mathematical proof,
>> and if you're talking about that, you're not talking about C++.
>
>I don't think anyone claims otherwise. See the last point in the link I
>posted.
Proponents of TDD in the Martin, Beck, Jeffries sense really do
try and push it too far. I wrote about this some time ago:
http://pub.gajendra.net/2012/09/stone_age
See, for example, Martin's comments here:
https://sites.google.com/site/unclebobconsultingllc/home/articles/echoes-from-the-stone-age
(The first comment on his page is pretty spot-on.)
See also this post, and look for Martin's comment:
http://ravimohan.blogspot.com/2007/04/learning-from-sudoku-solvers.html
There, Martin tries to make a vague analogy connecting Ron
Jeffries's failure to produce a working sudoku solver to kind of
martial arts mysticism, wherein Jeffries is a venerable master
engaging in a mysterious kind of exercise that's so abstruse as
to be essentially unknowable to all but the most senior of the
initiated. I call shenanigans: Ron Jeffries simply didn't know
what he was doing and while yes, it took some courage to fail
publicly, the inescapable conclusion is that TDD is insufficient
as a design paradigm.
Peter Seibel's blog post is required reading on this debacle:
https://gigamonkeys.wordpress.com/2009/10/05/coders-unit-testing/
>> Two, there is a significant amount of validation that cannot be
>> approached through unit tests, I'm thinking particularly of
>> simulation, where we need to run code for hours and calculate the
>> statistical properties of outcomes.
>
>That's correct, there should always be multiple levels of testing, again
> I don't think anyone claims otherwise.
They most certainly do; repeatedly and in public. It might be
that they do not believe it themselves, and are only saying so
because they are (most commonly) consultants and authors who are
trying to sell engagements and books.
But there's a certain kind of cultish devotion that arises from
this that's unsettling: it's the sort of fervent devotion of the
converted, who claim that, "if you just genuflected THIS way..."
then all would be well.
The bottom line: unit testing seems to sit at a local maxima on
the cost/benefit curve, but there are many ways to get similar
quality results. However, unit testing is insufficient to
ensure that software is correct and responsive in all respects
and TDD, in particular, seems like something of an oversold fad.
- Dan C.