Re: Recursive functions



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. :)

.



Relevant Pages

  • Re: Recursive functions
    ... recursion is certainly a natural way of defining the ... it IS totally inappropriate to compute ... not mean "inefficient in a typical C implementation". ... If I had an actual requirement to print the string ...
    (comp.lang.c)
  • Re: Recursive functions
    ... function to compute the length of a string. ... It is a natural way of defining the length of a finite sequence ... it IS totally inappropriate to compute ... not mean "inefficient in a typical C implementation". ...
    (comp.lang.c)
  • Re: Article on Herbert Schildt, author of C Unleashed, repaired on wikipedia
    ... that deliberately went one beyond the end of the string, ... Within its framework, which sucks, it is a correct program. ... To do this you changed a value parameter to a reference parameter and ... this makes the recursion go wrong. ...
    (comp.programming)
  • Re: Three Kinds of Logical Trees
    ... > I think this is just a representation issue. ... > I do have a number, but I am only ttreating as a string. ... I was attempting to isolate the question of tree structure; ... it's not much of an issue; no one uses recursion much. ...
    (comp.databases.theory)
  • Re: Recursive functions
    ... function to compute the length of a string. ... to define the length of a finite sequence in terms of recursion ... :) I've never taught any programming courses, ...
    (comp.lang.c)