Iterative vs. Recursive coding
martin at address-in-sig.invalid
Sat Aug 21 02:24:18 CEST 2010
On Fri, 20 Aug 2010 16:22:44 -0700, Baba wrote:
> For the purposes of learning programming i think it's a must to
> understand Recursion so thanks all for your help!
That depends on the language and/or hardware. COBOL wouldn't understand
recursion if hit on the head with a recursion brick and early computer
hardware (those without a stack) made it VERY hard work. If you don't
follow this, look at the CODASYL language specification for COBOL or the
hardware design of ICL 1900 or IBM System/360 mainframes (which are still
the heart of the financial world) and work out how to implement a
recursive function for any of them. Its not easy but it can be done.
> Ok so now i hope you all agree that my code is also correct :)
Yes: it runs and does what I'd expect. A good result.
A basic skill for a programmer is to understand the specification for a
piece of code and write test cases. This is a set of inputs (both
expected/sensible and totally out of order) and the expected outputs from
each set of inputs. Then you write the code and run it against the test
cases to show that it does what the specification requires.
Never bullshit yourself or anybody else about this conformance to spec:
either you screwed up or, hopefully less often, the designer wrote an
ambiguous or plain wrong requirement. Either way, the problem must be
resolved and the code be made to do what is wanted.
while (results don't match the spec):
Rince, wash, repeat.
martin@ | Martin Gregorie
gregorie. | Essex, UK
More information about the Python-list