A great theoretical approach that rarely, if ever, works in workaday
programming. I have been promised many times the opportunity to
refactor software, then been forbidden to do so based on variants of,
"If it ain't broke, don't fix it."
I have learned that I must do it right the first time, because
management rarely permits, and then not willingly, the opportunity to
improve it.
I agree with you that following the "do it badly now, we can fix it later"
road will lead you into quagmires and infernal realms.
But that's not quite how i read blueparty's dictum; i thought he was
saying that when you don't have a lot of time, you choose the option that
you can actually get done, not the one that's best in some more general
sense. The point being that it's better to deliver something crufty than
to not deliver at all. "Real artists ship", as i've said elsewhere on this
group today. Of course, in reality, choosing the high road of Doing It
Right No Matter How Long It Takes doesn't mean you won't ship, it just
means you'll ship late, or have less time to do everything else that needs
to be done, but that's also a bad outcome.
I have also learned that it's no slower, and usually faster, to create
an optimal solution up front.
That's the crux. I certainly agree that sometimes it's worth spending a
bit longer on a task to build something that's going to be a better
foundation for tomorrow. But sometimes, that effort turns out not to be
necessary, or your idea of what was better turns out to have been wrong,
in which case the extra time is wasted. I have absolutely no idea of the
relative frequencies of these cases - clearly, you believe that the former
is more typical.
One of the axioms of XP is that you should always write the code that's
necessary to solve the problem immediately at hand, not some potential
future problem, which has some bearing on this situation. However, i don't
think any but the most fundamentalist XPist would argue that this means
you should do everything as a quick hack.
Agile shops are sort of an exception to this,
In theory!
but I have not had the privilege of working in those environments.
I am lucky enough to have that privilege, but even here, we have a
pragmatic (or 'lazy', if you prefer) approach to tidying up our mess. When
we come across something foetid in the codebase, rather than dropping
everything else to fix it, we tend to ask "is this hurting us?", and if it
isn't, just leave it as it is. There are a few specific things i can think
of in our current project that have been bugging me for months now (one
major duplication of functionality, one pointless inconsistency), but
which we still haven't got round to fixing, because they doesn't really
matter - or rather, they matter less than adding the next feature, or
fixing an actual bug.
Although the duplication (where there are two classes A and B which have
pretty similar behaviour) has meant that in another class which has to do
some stuff with a collection of As and Bs, there are separate but very
similar methods for doing that stuff, which means it actually has hurt us.
If i'd been writing the stuff-doing code, i would have taken the
opportunity to refactor, but i wasn't, and the guy who was doing it is the
guy who generated the A-B redundancy in the first place. I get the
impression he believes that the duplication is actually a Good Thing,
although we haven't really talked about why.
In my career, when I have refactored I've had to do it surreptitiously, and
put up with getting in trouble for it. The only exception was a team that
was ignored by management for six months, and therefore was able to redesign
the architecture on its own. The result was a 200-fold (not 200%, 200-fold)
increase in productivity for adding features to the product, and a change
from unreliable results to completely reliable results.
Incidentally, this is in line with the theory of software project
management, as described in several books I've read on the subject.
The strangest thing about this to me is that both the theory of software
development and of software project management supports behaviors that
managers I've worked with will not usually trust.
This probably won't come as a surprise to anyone who's familiar with the
work of Scott Adams.
Theories like keep an effective team together even during periods of
inactivity, or the tenets of agile programming. Despite the
anti-academic prejudice expressed at times in this thread, the theories
are actually more pragmatically useful than many of the practices of
less theoretically-inclined practitioners.
This line of argument has a slightly scarecrowish look to it; those of us
proposing the lining up and shooting of computer scientists (and perhaps
by extension, managementologists) are not proposing their replacement with
reason-averse buffoons of the breed all too often found in corner offices,
and thus the abandonment of any and all good ideas. Although that's
certainly a common outcome in real-world situations where intellectuals
have been purged - one of the few things i took away from my high school
history lessons!
tom