Why I Recycle Programming Problems

On my second time through, I gave myself a simple constraint: solve the problem again without a for loop..In other words, I had to try another approach.So I tried using a set, and my resulting program became cleaner and more readable..Then, I took it one step further with another constraint: solve the problem with another variation of a set..In total, I reduced the amount of code for this program by more than 50%..And I learned a lot about sets in the process!Other times constraints end up complicating my code..In one recycled problem I gave myself the constraint to use a while loop, and the program became long and complex; the for loop I had used on a previous iteration was a better option..Even still, repeating a problem with a constraint helped me understand when it’s advantageous to use one approach over another.Despite the result, repeating a problem with constraints gets me outside my comfort zone and makes me think in new and creative ways..I usually get stuck and have to do some research..In the process, I pick up details I’d overlooked and learn new ways of doing things.Learning to Write TestsI’m on my third time through the dozens of problems in Brian Hogan’s book Exercises for Programmers..I’ve had a different intent for each iteration..This time through I’m practicing writing my own tests.This is how it works: I pick a problem at random from Hogan’s book and solve it..I organize the program into separate files; each file is responsible for a different part of the solution.. More details

Leave a Reply