Re: Recursive functions



On Apr 1, 7:35 pm, "Bill Pursell" <bill.purs...@xxxxxxxxx> wrote:
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.

I don't agree. Practical concerns should be secondary during the
learning process, or else the learning process only allows the
programmer to familiarise himself with limited techniques. The first
question should always be one of readability. Additionally, recursion
in the form that would be used by array length functions gets replaced
with iteration forms by certain modern compilers, taking away from the
practical concerns.

.



Relevant Pages

  • Reply to Gerry Quinn - Perils of Java Schools.
    ... >> Most Java(any imperative language) programmers will instinctively opt ... >> for an iterative solution and will only use recursion when they are ... In those situations your imperative programmer takes a lot ... > abandon Java in favour of a toy language that is limited to them and no ...
    (comp.programming)
  • Re: Interesting article by Joel Spolsky: The Perils of JavaSchools
    ... >> Most Java(any imperative language) programmers will instinctively opt ... >> for an iterative solution and will only use recursion when they are ... Ask an average Java ... In those situations your imperative programmer takes a lot ...
    (comp.programming)
  • Re: Interesting article by Joel Spolsky: The Perils of JavaSchools
    ... >> Most Java(any imperative language) programmers will instinctively opt ... >> for an iterative solution and will only use recursion when they are ... Ask an average Java ... In those situations your imperative programmer takes a lot ...
    (comp.programming)
  • Re: Interesting article by Joel Spolsky: The Perils of JavaSchools
    ... >> Most Java(any imperative language) programmers will instinctively opt ... >> for an iterative solution and will only use recursion when they are ... Ask an average Java ... In those situations your imperative programmer takes a lot ...
    (comp.programming)
  • Reply to Gerry Quinn - Perils of Java Schools.
    ... >> Most Java(any imperative language) programmers will instinctively opt ... >> for an iterative solution and will only use recursion when they are ... In those situations your imperative programmer takes a lot ... > abandon Java in favour of a toy language that is limited to them and no ...
    (comp.programming)