Monday, March 7, 2011

Day 5: Balderdash!

Today was crap! After work I went through one Chessmaster lesson while I ate and then immediately dove into the computer programming. Yesterday, I finished the fourth chapter in the book, which is about one third through. After each third of the book is a lab exercise. They give you a more complicated example that will make use of the things you've learned over the past chapters. That lab is what I just spent about 4 hours doing.

From a beginner programming standpoint, the program is a cool idea. It's a racetrack simulation. The kind with emaciated doggies. Basically there are three people, Joe, Bob, and Al, who bet on the four dogs. There's no complicated bets. They each get to pick one dog and can bet between 5 and 15 dollars. If that dog wins, they get double their bet back. If their dog loses, they lose their bet. That's what the bottom half of the program is for, managing the bets for the three guys. The top half is a simple four lane race track (think straight lines) and a picture of a greyhound that slides from left to right at random intervals.

The problem is in the emphasis on object oriented programming, which admittedly is the purpose of the book and the power of the language, but I'm certainly not well versed enough to handle the problem. I gave it a solid effort but made very little headway. It was a good wake up call that I'm not paying nearly enough attention to these exercises. I mean, I'm completing them, and going through the motions, but obviously I'm not gleaning all the knowledge that I am meant to.

The end result of this failure? I cheated and looked through some examples done by others in the forums of the publisher. It's funny because one of the things it specifically emphasized was the "this" keyword in which you have an object refer to itself. They wanted us to use it, and the examples I found worked around it every time.

Tomorrow while I'm at work, assuming I have any time, I'm going to think of a similar problem that has slightly fewer moving parts, and when I get home I'll work to make that program instead. If any of you have suggestions on something that you think might fit the bill, leave a comment. That's all for tonight.

1 comment:

  1. I'll think of something if you want. I always have ideas, often really, really simple ones.

    As for the "this" keyword, it's up for debate in the community. A lot of people really like using it and think it should be used whenever possible, while others think it's just a waste of effort and time, and should be worked around in some way (most often having the class variable be the exact same name as the function argument, only with an underscore tagged on the front). There's a whole range of tripe that goes on in the community, though, so it's basically up to you and/or your employer: They will often have style standards that have to be met.

    Incidentally, looking through examples on the forums is an "okay" way to solve certain problems. You have to be careful with it, not because you've in any way sacrificed your intellectual responsibility, but rather because they are often quite terrible! Googling for an answer can help get an idea of how to do something at times, but should not often be the basis of an answer.

    ReplyDelete