Re: struct or class
On Jan 29, 4:36 pm, Ian Collins <ian-n...@hotmail.com> wrote:
On 01/29/11 02:11 PM, James Kanze wrote:
On Jan 28, 12:16 am, Ian Collins<ian-n...@hotmail.com> wrote:
On 01/27/11 10:41 PM, James Kanze wrote:
On Jan 25, 10:14 pm, Michael<mcmcca...@gmail.com> wrote:
Source code is, by definition, definitive. Documentation is, to one
degree or another, a work of fiction. They both have their purpose
and they both should maximize human-readability.
Human readability only goes so far. Good programmers don't
write a line of code until they know what it is supposed to do,
and you don't know anything unless it is written down.
Written down in code, as a test!
A test is the definitive, up to date documentation for the
code it tests.
So how do you know what the test should do? And tests are
certainly not documentation; they're generally even less
readable than the sources, they only treat specific cases, not
the general rules, and they don't provide a necessary overview.
I don't see how you can say something that unambiguously
states what the unit under test must do isn't documentation.
Prose is open to misinterpretation, code isn't.
Show me a test suite that unambiguously states that the result
of some floating point function must be accurate to 1/2LSB.
Show me a test suite that unambiguously specifies the
requirements that client code must meet in order to use the
class safely in a multithreaded environment. For that matter,
show me a test suite that unambiguously specifies the
preconditions a client must meet, or face undefined behavior.
Even the word "documentation" has many meanings. I have just
completed a project where the deliverables were the code, the
unit tests and the acceptance tests. The last two were the
documentation requested by the client. I have also worked on
a project for the US DoD, where the documentation weighed many
Kgs...
Avoid both extremes:-). I've also worked on a project where
the quality of the documentation was measured in kg.
Write enough documentation up front so that someone who's
unfamiliar with the project could write the code. Other than
that, fairly little: pre- and post-conditions for functions,
possibly class invariants, and the exceptional case where for
some reason, you've had to do something unexpected.
--
James Kanze
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]