If you were a cat, a bug is a bit like a mouse that makes an
appearance only every week or so. You have to take full advantage of
every observation.
Nicely put
For code of any complexity I like to just watch it run in a debugger
for a goodly while and make sure everything that happens is what I
expect. 95% of the time strangenesses are actually ok. Surprises are
easier to spot than bug droppings.
I'm not sure about that 95% of the time, but even were it true you'd want
to make sure you were actually in that 95%. Debugging / profiling is a
necessity in modern systems - sad but true. The average Java is so far
removed from the machine, and usually with parts from many sources, that
you just can't hold it all to account otherwise. For example, I can't
remember the last time I did anything bitwise If my experience has taught
me anything, it's that computers aren't supposed to surprise me.
Of course writing a test harness to thoroughly exercise any class is
your best insurance, but it won't catch everything, e.g duplicate
actions.
I love it when you see a project that's obviously been written test-first,
and they've got clover on there, and made it a roadmap target to "reach
100% coverage" - like it's a deliverable. So you look through the pretty
(enormous) clover reports and sure enough, every statement has been
executed (apart from those few they excluded at the last minute), and all
the bars are green. Every class _works_, as demonstrated by the fact that
each and every method has been called with a carefully contrived set of
arguments by another method. Sometimes several times.
Of course, any newbie can write a class to spec - it's Java 101. Writing
classes that work, _together_, in the wild, well... that's just not what's
driving the design.
How many products / projects have you seen that didn't work, or didn't
perform, purely because no-one had checked the impact of everything
working _at the same time_ during development?