* Daniel T., on 25.09.2010 20:36:
I realize your questions were ment to be rhetorical, but I think the
correct answers are a little less obvious that you seem to think.
1. There are a whole host of ways to write programs that an expert would
not even consider worthy of mention (this may very well be one of them,
I can find no style guide that forbids such constructs as the OP
mentioned.) If we were to try to write *all* of them down, not only
would the tome be voluminous, but the debates among the highest quartile
about the finer points would be un-constructive.
This one is simple, I think. Aim for /clarity/. If the people that one works
with don't understand clarity, e.g. if they think that it can be reduced to
mechanistic robot-enforced rules, then mostly all is lost anyway.
2. Rules and limits do indeed breed creativity, but we must be careful
that the creativity isn't directed toward getting around those very
rules and limits.
Yeah.
3. Given a specification for a function or class and code that does not
meet that specification, what should a "maintenance" programmer do? Try
to tweak the broken code, or erase and re-write the function or class so
that it works correctly? Unlike in building construction, destroying old
code isn't a costly procedure. Unlike in surgery, it is rarely the case
that we have to keep the program alive while working on it. These facts
afford us much more latitude in "starting from scratch."
Uhm, the cost of replacing old code can be /very/ high. For example, I once had
to structure a piece of code in a base class so that part of it could be
overridden. This could conceivably have been done in a fifth or tenth of the
time if the thing could just be replaced, but it wasn't documented, and it was
absolutely not clear what the heck it did, relying on umpteen (effectively)
globals and sideways initialization at unpredictable times and returning at
various points in apparently different states, with this spaghetti in turn
embedded in a system-wide spaghetti of interactions. Replacing it would mean
replacing also large parts of the connected spaghetti. It's at times like those
that you wish your boss was someone you could explain things to and ask for a
decision. It's sort of hard to justify the work otherwise: anyone looking at the
code, not knowing the complicated rationale, will most naturally see it as
further obfuscation of already spaghetti (I am sure of that, since Someone(TM)
anonymous asked in this group, later, about that code, it couldn't be anything
else because I used a very special technique to transform it while keeping its
functionality as-is, and the question was about the point of that technique).
Cheers,
- Alf