Re: [Algorithm] Sum of Primes < 1000000
Patricia Shanahan wrote:
I did that once, and created a lot of trouble. It was a system for
managing and applying patch cards when booting an operating system. I
was told that there would never be more than order tens of cards at a
time, before the OS would be recompiled with source code changes.
I did a very simple implementation that I knew was O(n^2), but that I
had tested for a couple of hundred cards, several times the number
required by the specification, and at that size it ran about as fast as
the card reader.
Over the years, the number of cards increased to about a thousand, and
it became a real bottleneck. I tried to explain the issue, and get
permission to rework the code to use e.g. a tree structure or a hash
table instead of a linear search...
A lot depends on your confidence that reimplementation will be permitted
if the problem outgrows the O(n^n) solution.
Over the last thirty or so years, I have seen many projects where we were told
"we can always refactor it later", but later were told, "we are not going to
refactor given the investment in the existing codebase, besides it works,
doesn't it?"
As a practical matter it is almost impossible to get management buy-in to
throw away existing code no matter how terrible. One worst case scenario was a
nine-month project that had cost my employer nearly a million dollars to a
cosultant, and still didn't work - it gave wrong results and crashed the host.
(The consultant was known in our trenches to be a scammer, but we never could
convince management of that.) I stepped in, took two days and about 150 lines
of code (including blank lines and comments) and created a complete,
bulletproof solution. (Not actually a difficult project, you see - the
consultant was a scammer.) I nearly got in trouble, since I had completely
disregarded the nine months / million dollars worth of existing code that
didn't work. As it was, I was the focus of a lot of managerial concern. (They
always looked so sad when I told them, "Port Steve's code? I never even looked
at Steve's code; I just rewrote the application from the specification.") The
investors pulled out all their money from the company two weeks later
(possibly for unrelated reasons). Welcome to the future.
There has to be an awful lot of pain before there is buy-in for refactoring,
and often not even then.
- Lew