[Exceptional C++ Style] Item 18 - Virtuality

Terje Slettebø tslettebo at broadpark.no
Wed Jan 5 11:01:56 EST 2005


>Timothy Wright <tcw321 at gmail.com>:

> However, I am still at a loss on how to define a
> good design, regardless of language.  I measure it by coding something
> and see if it gives me trouble in the next few months.  Trouble in the
> sense of repeating mistakes, making many small corrections etc.  When
> do I know if I have a good design?

One guideline or indicator may be the "code smells" that Kevlin mentioned from
Fowler's "Refactoring" (in this case, "speculative generality"). A sign of that
is if you have code that is only exercised by tests (if even there). Thus, you
have unneeded complexity.

> Then I get a new requirement that
> blows away what I have done.

Precisely because of changing requirements and evolving systems, it's important
to "travel light". The "old school" was to try to anticipate every concievable
way the system might need to evolve, and build in flexibility for that from the
beginning. However, if you're wrong, you've just done unnnecessary work, and
having had to maintain it, for no reason. Moreover, even if you're right, you
may have had to work with increased complexity for a long time before you may
need it.

Thus, unless you're pretty sure you need something, and/or it's hard to refactor
the design to it later, it may pay to postpone it. The "new school" is to keep
the system in shape (refactored), so that you may change it any way you need,
when you need to. Adaptability, rather than trying to predict.

Regards,

Terje



More information about the Effective-cpp mailing list