Re: Recursive functions
- From: "Bill Pursell" <bill.pursell@xxxxxxxxx>
- Date: 1 Apr 2007 14:07:46 -0700
On Apr 1, 9:24 pm, "Bill Pursell" <bill.purs...@xxxxxxxxx> wrote:
On Apr 1, 9:10 pm, Lauri Alanko <l...@xxxxxx> wrote:
In article <1175456107.493063.221...@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
Bill Pursell <bill.purs...@xxxxxxxxx> wrote:
Because it is totally inappropriate to use a recursive
function to compute the length of a string.
"Totally inappropriate" apparently means here "inefficient on a
typical C implementation". That is certainly true, but not always
crucial. Even the space performance isn't an issue if the lengths of
all argument strings are known to have a reasonable bound.
Efficiency aside, recursion is certainly a natural way of defining the
length of a sequence.
It is a natural way of defining the length of a finite sequence
in a mathematical setting. It is not completely unnatural
to define the length of a finite sequence in terms of recursion
on a computer. However, it IS totally inappropriate to compute
the value using recursion. Totally inappropriate does
not mean "inefficient in a typical C implementation". It
is, rather, a euphimism for "completely boneheaded".
I should probably learn to pause for at least 10 seconds
before posting, if only to catch stupid spelling errors.
To clarify why I think it's wrong to use recursion in
this case: things should be kept as simple as possible,
but no simpler. The standard library provides strlen,
and "return strlen( a );" is simpler than
"return 1 + reclen( a + 1 );". I'm actually not at
all concerned about efficiency of the implementation,
and in fact it wouldn't bother me if strlen were
implemented as a recursive function. Well, maybe not. :)
.
- References:
- Recursive functions
- From: Harry
- Re: Recursive functions
- From: Bill Pursell
- Re: Recursive functions
- From: Harald van Dijk
- Re: Recursive functions
- From: Bill Pursell
- Re: Recursive functions
- From: Lauri Alanko
- Re: Recursive functions
- From: Bill Pursell
- Recursive functions
- Prev by Date: Re: when can realloc fail?
- Next by Date: Re: when can realloc fail?
- Previous by thread: Re: Recursive functions
- Next by thread: Re: Recursive functions
- Index(es):
Relevant Pages
|