Re: Recursive functions



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.

.



Relevant Pages

  • Re: primitive recursive: obsolete?
    ... Because not all total recursive functions are recognisable as such by ... that the principle of definition by primitive recursion is equivalent ... arithmetic as the canonical formalisation for finitism; ...
    (sci.logic)
  • Re: Need help with Python scoping rules
    ... suggests that Python does not fully support class-level encapsulation. ... on recursion. ... ret *= i ... Recursive functions should be OK wherever functions ...
    (comp.lang.python)
  • Re: No machine stack and C
    ... jacob navia wrote: ... includes recursion and simulates the stack in software. ... the recursive functions. ...
    (comp.lang.c)
  • Re: Are recursive functions ever needed?
    ... In mathematics, recursion is commonplace, and is frequently used to define ... recursive functions are at their best when a problem can be ... A bunch is defined as 0 or more ... If a recursive solution is elegant, however, think twice before using it! ...
    (comp.programming)
  • Re: Problems reversing strings
    ... Oh, I agree that this is not one of C++'s strenghts, but learning to ... use recursion is part of learning to program. ... the programming mind. ... > templates) but it is almost always an inappropriate solution in straight ...
    (alt.comp.lang.learn.c-cpp)