I’ve had my students working on a little exercise this week. It’s simple and I know that a lot of teachers use similar projects. The idea is to build a triangle or in this case two of them. You can see what I am looking for on the right.
Now as long as I have seen this project I have always used nested loops to generate the triangles. The outer loop controls the rows and the inner loop the columns. It’s a pretty natural way of thinking especially when it comes in the middle of a unit on loops in a first course. As far as I can recall all of my students have solved this the same basic way – nested loops.
Today I was trying to help a struggling student and realized that there was a way without nested loops. Well it turns out there are several ways one can do this. At least one depends on knowing about some methods built in to the string class in the .NET platform. Other ways should be easily determined by beginners so I’ll not go into that here. Besides, that is not the point of this post.
The point is that it is easy to get into ruts. Easy to fall into the same old solution time after time even as we add more tools to our toolbox. From time to time it is helpful to step back and look at old problems with new eyes. Grace Hopper used to promise her audiences that if they ever said “we’ve always done it that way” she would appear and haunt them. I can’t hear that phrase without thinking of her so I guess she was serious.
I wonder what other old projects I should be taking a new look at?