I know I just recently talked about recursion in a post, but I have heard too many complaints about recursion lately to not address it.
I understand that loops are a comfort zone, but that doesn't always make them the easiest way to solve a problem. I will admit it takes a while to get use to the way to think for recursion, but once you get it, it brakes down problems really easily and clearly. During the lab last week, the last question was solving the first question without recursion. With loops it took me an hour and a lot of lines of code, whereas the recursive algorithm took me under 15 minutes and only a few lines.
Dear Recursion,
Let the haters loop. They are just stubborn in their coding practices. If they just got to know you, they would love you like I do. You run so elegantly and are truly beautiful. You do so much with so little, it's amazing. The base case for my love will always return true for you.
A SLOGing Good Time
Sunday, 3 November 2013
Sunday, 20 October 2013
Object-Oriented Programming and Recursion
Object Oriented Programming is a way of structuring code to create "objects" that groups relevant variables and functions (methods) together. It really helps when someone is writing a larger or more complex program but even smaller programs can benefit from OOP. It helps to organise and clarify for others reading the code as well as the programmer. The ability to create your own objects means that you are not restricted to built in data types and objects. A programmer can create an object that is tailored perfectly to the program's needs.
Recursion is when a method or function calls itself. In order to stop infinite recursion, there is one or more base cases. Once one of these cases is met, return values are then sent back up the recursion chain until the original call to the function is reached. Recursion, although less straight forward than loops, is extremely helpful to programmer, often shrinking a long series of loops and if statements to just a few lines of code. Some problems are very difficult to solve without recursion, making it a very important tool for programmers to possess.
Recursion is when a method or function calls itself. In order to stop infinite recursion, there is one or more base cases. Once one of these cases is met, return values are then sent back up the recursion chain until the original call to the function is reached. Recursion, although less straight forward than loops, is extremely helpful to programmer, often shrinking a long series of loops and if statements to just a few lines of code. Some problems are very difficult to solve without recursion, making it a very important tool for programmers to possess.
Sunday, 29 September 2013
Stacking that Cheese
I started work this evening on the first assignment with my partner. We finished up to where we could run the display and see all of the cheese. Ideally we would be able to move the cheese as well but the movement is not yet working fully. We're having some issues where cheese is sitting on top of ghost cheese. We tried top isolate the problem but sadly failed to narrow down the possible problem code. We decided to break for the night and work on it again tomorrow or Tuesday. Hopefully one of us will have a eureka moment while away or clearly see the problem when we look at the code with fresh eyes. At the very least we'll have more energy to try to fix the issue.
Subscribe to:
Posts (Atom)