Old Wolf said:
I don't think yours is significantly shorter -- there seems to
be about the same amount of program logic, but Richard used
more whitespace and longer variable names than you did.
Yep. I find that I can most easily maintain my own code if I can read and
understand it, and to that end I use whitespace and identifier names in
what I hope is a consistent and non-confusing way. If I were going for
brevity, I could obviously crunch everything up a lot more, but I prefer to
write in an exegetic style unless I'm deliberately going for obfuscation
(which is pretty rare, for me).
Good (IMHO). In Richard's version, he introduces a new variable
"done", whose sole purpose is a long-winded version of "break".
I'd like to hear his rationale on that...
I quite often get asked this.
Again, this is to do with my own imperfection. I'm actually pretty lousy at
figuring out what code is supposed to be doing, and since I have to
maintain my own code - often after months or even several years of not
having so much as glanced at it - I like to write it in such a way that I
can pick it up again easily later on. Since the biggest problem I have in
reading code is that of following "jump all over the shop" control flow, I
endeavoured to devise a programming style that minimised the jumpy aroundy
problems that so confuse me. To that end, I decided some years ago to try
to keep to a regimen of "one entry, one exit" for all functions and all
loops. On some (fairly rare) occasions I have departed from that, when I
think it's necessary to do so. On somewhat more frequent occasions I have
departed from it not because it's necessary but because it makes the code
slightly quicker to type - and on such occasions I invariably find myself
going back to that code to "do it properly", so to speak. I guess that's my
conscience speaking.
A word about the answers site may be in order. I started that off back in
January 2000 (I think), and kept it going for a couple of years, but I
found it harder and harder to keep apace of contributions, notably from one
Gregory Pietsch (whom I seem to recall I treated most abominably, for he
sent me loads of solutions which I never quite got around to posting - I
hope he's forgiven me by now). Eventually I simply gave up altogether.
I cannot in all conscience commit myself to resurrecting the answers site,
for I simply don't have the time. In any case, I no longer own that account
- it's only still up either out of the kindness of Powernet's heart or
because it's been overlooked somehow - so I couldn't update it if I wanted
to.
If someone with more time to spare than me wants to grab all the solutions
from that site while it's still up, and use it as the basis for a
rejuvenated answers site, I have no problem with that personally. I don't
know what copyright law says about the matter, so whoever takes up the
baton may need to contact the authors of the individual solutions to ask
their permission to reproduce those solutions.