lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On this day of 03/15/2007 06:34 AM, Alex Queiroz saw fit to scribe:
>     Well, I hardly take chances with a call stack. In fact, I think
> the last time I used recursion in C was in college. It was the
> floodfill algorithm for painting geometric figures, and it taught me
> to never recurse in C again.
>     Recently I had to write a minimal XML parser in C for a mobile
> phone application. Of course I didn't write a recursive parser,
> because of the memory limitation. Would I have written a recursive one
> if it was a PC application? I doubt it. Constant-space algorithms give
> you warm feelings that you aren't throwing dices.

I see your point. A lot of recursion done in school in C or Java (or
almost any procedural/OO language) is somewhat contrived for the sake of
teaching recursion. I have had to explain several times why in the world
we are taking a recursive solution for some problem...

It is hard to me to argue personally about the "in college" part because
I'm still in grad school, but I often write programs in C(++) or Java
that use recursion, and not just because I was told to do so as part of
an exercise.

An example that is relevant to me these days is a logical prover system,
with a language somewhat similar to Prolog. I shudder to think how I
would write the same thing without recursion.

Still, all this goes to show that you can still understand and write
recursive code in C (or Java or whatever). It might not be the most
appropriate or the safest solution (w.r.t. the call stack), but you can
still do it and understand recursion.

Cheers,
- David

-- 
~David-Haley
http://david.the-haleys.org