www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/12/20/22:55:24

Message-ID: <385EF125.235D17E6@lycosmail.com>
Date: Mon, 20 Dec 1999 22:16:53 -0500
From: Adam Schrotenboer <ajschrotenboer AT lycosmail DOT com>
X-Mailer: Mozilla 4.7 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Re: Use of recursion
References: <82vfqn$6ce$1 AT mango DOT singnet DOT com DOT sg>
Reply-To: djgpp AT delorie DOT com

To quote (from memory from a book on C++ I have, and probably
paraphrased):

Recursion is useful in cases in which it is the most intuitive solution.
In some cases, the iterative solution is only derivable if the recursive
solution has already been developed.

Not much of a help, but in my opinion, code in recursive. It's generally
more intuitive, and if you are careful, and make it tail-recursive, then
many (optimiziing, like GCC) compilers can optimize the code to be
iterative, while maintaing the simplicity of coding that recursion allows.

Yong-Kwang Goh wrote:

> I've a function that draws borders around bitmaps to make them
> appear outset (popup) or inset (sunken). In anyway, it means giving
> the bitmaps a 3D look if you don't get what I mean.
>
> Somehow, it can be programmed to achieve the effect in 2 ways:
> using recursion or normal looping.
>
> Now, I've a dillema -- should I use recursion or looping after all.
> AFAIK, recursion is a very useful and good programming technique,
> but one which gobbles up computing resources and *must* be
> used carefully. Looping is more efficient but usually more complicated
> than using recursion.
>
> I wonder if recursion *is faster* than looping.
>
> When should I use recursion since it can be replaced with looping
> most of the time?
>
> Could someone enlighten me on this issue?

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019