David Rubin wrote:
[color=blue]
> Phlip wrote:
>
> [snip][color=green]
> > I (authoritatively) define coupling as "A must change only because B
> > changed."[/color]
>
> s/change/re-compile/[/color]
That is an artifact of how C++'s compilation model weds most kinds of
coupling to the recompile system. Put another way, you can build very large
systems in C++ without excess recompiles if you take care to follow good OO
design principles such as "program to the interface, not to the
implementation".
But you can still couple A and B unfairly, but A _doesn't_ recompile when B
changes. It just breaks.
[color=blue]
> [snip][color=green][color=darkred]
> > > How to avoid such cases?[/color]
> >
> > Write lots of unit tests. Write them before writing the tested code, and
> > make them fail before making the tested code pass. Then refactor,[/color][/color]
testing[color=blue][color=green]
> > every few edits, until your design contains no duplicated definitions of
> > behavior.[/color]
>
> To me, this approach encourages you to design to the unit test suite
> rather than to the problem domain. I have never had a good experience
> writing tests before I write the interface, but I guess it's good to
> experiment.[/color]
One designs them both, together, in tiny increments. One doesn't write many
test cases up front.
[color=blue][color=green]
> > Those forces overwhelmingly crush out all possible coupling from your
> > design. Under such a system you honestly needn't fret about coupling; it
> > becomes a non-issue, like bugs.
> >
> > For example:
> >
> > int main()
> > {
> > Source aSource("a b\nc, d");
> > string token;
> > token = aSource.pullNextToken();
> > assert("a" == token);[/color]
>
> FWIW, I find it useful to define and use ASSERT (or redefine assert())
> so that it doesn't stop the program execution at each failed
> assertion.[/color]
Yes! ASSERT() should invoke a breakpoint expanded in the calling function,
not deep in the C++ Standard Library.
[color=blue]
> Otherwise, you may have to run the test driver several
> times to solve one class of error.[/color]
No! If you run the tests every 1~10 edits, and predict the results of each
run, then any unexpected failure is cause to simply Undo the most recent
edits.
--
Phlip
http://industrialxp.org/community/bi...UserInterfaces