Software bugs aren't inevitable

François Pinard pinard at iro.umontreal.ca
Thu Sep 15 21:10:54 EDT 2005


[Jerzy Karczmarczuk]

> Steven D'Aprano recommends iteration over recursion:

> > For instance, try these two simple functions for the nth number in
> > the Fibonacci sequence:

> > def fibr(n):
> >     "Recursive version of Fibonacci sequence."
> >     if n == 0:  return 0
> >     elif n == 1:  return 1
> >     else:    return fibr(n-1) + fibr(n-2)

> [...] please refrain from giving nonsensical examples, since NOBODY
> serious programs something in the style of your recursive version.
> Such anti-advertizing of recursion says less about the recursion than
> about yourself. [...]

I did not look recently, but many introductory texts to computer
science, and many, many "serious" teachers as well, introduce recursion
using Fibonacci numbers and Towers of Hanoi.  So, there is no need to be
harsh on your correspondent, unless you feel like being harsh on a whole
generation of teachers as well! :-)

This being said, for one, I always found _insane_ presenting recursion
to new programmers using such examples, which are both very easily,
and much better written non-recursively.  It does not help beginners
at taking recursion any seriously.  This is handicapping somehow, as
recursion could be so useful when properly understood and applied.

-- 
François Pinard   http://pinard.progiciels-bpi.ca



More information about the Python-list mailing list