Joe Wright said:
I'm trying to read the paragraph above. How should main() become foo()?
You write what you think is an application. It has a main() and everything.
It's huge. Easily a quarter of a million lines. It goes into production. A
few years later, someone spots that it isn't /really/ an application - it's
just a library routine! And so they s/main/foo/ (or some more fitting name,
obviously), and call the thing over and over again, in a loop. Suddenly,
memory is dripping out of the side-panels and forming puddles under the
raised floor.
When I was at MumbleCo, I was working on just such a program. Unfortunately,
at the time I didn't have the clout to make the project lead realise the
importance of good housekeeping. Along with quite a few others, I worked on
that program for over a year, and then it finally went in, and I wandered
off to greener pa$ture$, as they say.
Some years later, I found myself working for CoughCo, who had paid MumbleCo
a significant sum of money for the program (I don't know whether it was a
transfer of ownership or a mere licensing deal, and it doesn't really
matter for the purpose of this account). It was no coincidence that CoughCo
hired me, of course. They were after my experience of the program.
Anyway, CoughCo decided that this wasn't a program really. It was just a
subroutine. Admittedly, at 250KLOC or so, it was a rather *big* subroutine,
but a subroutine nonetheless. And so they gave main a new name, and called
it from their own main. In a loop. And that's when the memory usage hit the
ceiling.
Good housekeeping isn't just pedantry in practice. It's part of defensive
programming.