In article <um********************************@4ax.com>,
bl***@blank.com
says...
[ ... ]
I want to get everyone's opinion on the use of recursion.
That's a bit like asking "I want people's opinions of large trucks."
It's so vague as to be nearly meaningless.
Should we readily use it when we can or only when absolutly forced to
use it?
IMO, you should readily use it when doing so will lead to code that's
easier to read and/or write than doing otherwise. Using it to create
simple loops is pointless except in languages (e.g. LISP) that don't
really support loops directly, or in situations (e.g. template meta-
programming) where the language does, but not under the circumstances
you care about.
OTOH, there are also times that recursion seems to be a natural fit, but
ends up working relatively poorly. Elsethread, traversing a tree-like
file system has been mentioned, so I'll use it as well. The problem
here is that traversing a tree-like file system recursively naturally
tends to lead to a depth-first traversal, but this tends to make
exceptionally poor use of caching. At least with all the OSes I've
programmed, if you care much about speed, you're almost always better
off doing a breadth-first traversal instead.
This way, you read an entire directory at once, and then go to the next
directory. This can avoid quite a bit of disk seeking as well as
improving cache usage. The difference depends a lot on the directory
structure, but if (for example) you were searching a large disk, a 10:1
speed improvement wouldn't be surprising at all.
--
Later,
Jerry.
The universe is a figment of its own imagination.