Re: Recursive functions
- From: "Bill Pursell" <bill.pursell@xxxxxxxxx>
- Date: 1 Apr 2007 12:35:07 -0700
On Apr 1, 12:46 pm, "Harald van Dijk" <true...@xxxxxxxxx> wrote:
Bill Pursell wrote:
On Apr 1, 6:37 am, "Harry" <geharipras...@xxxxxxxxx> wrote:
1)I need your help to solve a problem.
I have a function whose prototype is
int reclen(char *)
This function has to find the length of the string passed to it.But
the conditions are that no local variable or global variable should be
used.I have to use recursive functions.
Ask your instructor what the function should do if its
argument is not a string. Then ask your instructor
why you have been given an idiotic assignment which
will not help you learn to program well. Recursive
functions have a place, and this is not it. It is
unethical and/or incomptetent of your instructor to
teach you how to mis-apply a useful technique.
Why should this not be written as a recursive function? If you ignore
practical concerns which do not necessarily apply during the learning
process, do you have any reasons at all?
Because it is totally inappropriate to use a recursive
function to compute the length of a string. It may be
useful to do it as an exercise for the sake
of playing with recursive functions, but only if it
is strongly emphasized that using recursion is absolutely
the wrong way to solve this problem. However, it is
far better to teach recursion with examples for
which recursion is the correct solution method.
Practical concerns must be applied during the learning
process, or else the learning process is detached
from reality, and the end result is a programmer who
doesn't know when a technique is appropriate.
.
- Follow-Ups:
- Re: Recursive functions
- From: Harald van Dijk
- Re: Recursive functions
- From: Lauri Alanko
- Re: Recursive functions
- References:
- Recursive functions
- From: Harry
- Re: Recursive functions
- From: Bill Pursell
- Re: Recursive functions
- From: Harald van Dijk
- Recursive functions
- Prev by Date: Re: question about k&r2
- Next by Date: Re: Equivalent malloc with calloc
- Previous by thread: Re: Recursive functions
- Next by thread: Re: Recursive functions
- Index(es):
Relevant Pages
|