From: Chris White Date: 2011-09-29T10:30:41+09:00 Subject: Re: Tree - Recursive print function --_f690b5e5-47e9-4535-aada-a8258acae37a_ Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable > I'm working on a tree data structure at the moment and I'm having > trouble with the recursive print function. It seems that the function > simply restarts every time it finishes... Even though it is not a > infinite loop. Hope that you guy's can help me figure out what the > problem is. Instead of answering the answer directly I'm going to take a "teach a man t= o fish" approach. The Ruby community has many proponents of what is known a= s TDD or Test Driven Development. In essence the approach is to write a tes= t that will fail (missing class=2C missing file=2C incorrect functionality)= =2C then make that test pass. Then you write another test which will fail a= nd make that pass as well. Each test should focus on a specific piece of fu= nctionality.=20 Why is this important? Consider your situation now. You've written a giant = test which attempts to look at the entire class as a whole instead of the i= ndividual components. Now you're stuck trying to figure out which of these = components has an issue. If the TDD approach had been taken first=2C you co= uld have easily narrowed down the problematic piece of code and potentially= figured out what went wrong on your own.=20 I recommend taking a look at how TDD works. Here is a basic screencast to g= et you started: http://kanemar.com/2006/03/04/screencast-of-test-driven-development-with-ru= by-part-1-a-simple-example/ Write some tests for each piece of functionality in your class and see what= 's not working out. Regards=2C Chris White Twitter: http://www.twitter.com/cwgem = --_f690b5e5-47e9-4535-aada-a8258acae37a_--