[snips]
There's a strong case for making programs correct. There is also a
strong case for taking code that will almost certainly never be executed
out of functions.
No, there isn't.
There's a case to be made for removing code which *will never be
executed*. It's dead code, it serves no purpose.
If the best you can say about it is that it "will almost certainly never
be executed", you are admitting the possibility that it will be, at some
point - and the code in question exists for the express purpose of
dealing with those situations.
As a simple counterpoint to your view, I could discuss some of the
database code I've written. The code polls various devices, recording
the data into a database.
The DB server is on the same machine that the polling code runs on, and
it is launched, automatically, as part of the startup routines. In
essence, if the polling code is capable of being run, the DB server
should always also be up and running and available.
However, it isn't. A simple example is upgrading the DB server software;
if the polling code, which runs at scheduled times, happens to run while
the DB server is down, in the process of being upgraded, the polling code
cannot store the data to the server.
Since this is a rare case, I can, of course, simply ignore this, pretend
it all worked, pretend the data has been safely stored, and as a result I
can go ahead and zero the counters I've been polling, right?
Not blinkin' likely. For one thing, those counters represent *money*.
We record the data, we ensure it is recorded, or we *do not touch it*.
Period. End of question.
The fact that the DB being down when the polling code fires may be a rare
event is irrelevant; it is *not* an impossible event, and if it does
happen - and we use your design philosophy - we lose money. Simple as
that.
Except we don't use your design philosophy, we use one that actually
makes sense. We check for errors. We know they're rare, but we *also*
know that unless we can prove they will *never* occur, we must cope with
them - and that means leaving the error handling code in, despite the
fact it will "almost certainly never be executed". "Almost certainly" is
not "certainly".
Error handling exists for the express reason that "almost certainly
never" actually *does* happen, and if the code making that assumption
gets used widely - becomes part of a popular library, say, used by
millions of people every day - then "almost certainly never" becomes
"almost certainly, and probably damned fast".