Tuesday, May 22, 2012

What am I Inheriting?

Well I wanted to do all the exercises in chapter 7 but I find the one with imaginary numbers to be a bit mathy. I did not want to spend most of my time figuring out the math concepts. To compensate for this, I took advantage of using some of the contructs learned in an earlier chapter and made the code from exercises 1-4 more efficient. Instead of having 4 methods, one for add, subtract, multiply and divide, I created a single method, arith, which takes an extra character argument (one of +-*/). Then there is a switch statement that performs the appropriate arithmetic based on the argument. In addition to this, I made the script prompt the user for the 2 fractions instead of setting it up for the user. This is much easier to work with.

I am happy that I figured out everything and am getting things to work. I have made use of the [self method] construct and have done as much as I can to not be inefficient. To do this, most of the control has been put into the print method. The IDE is great and having it tell me instantly where the code problems lie is such an incredible plus, I know I would have never had been able to get 1/4 as much work done if I was still using the editor. I am sure I would have been frustrated to the point where I would not even think of alternative efficiencies.

This language is challenging for me and although I am getting things to work, and making things efficient, it feels like the retention is minimal. When in code, I am fine. I think if I had to create stuff from my head, there would be trouble. I am hopeful this will change soon.

I started Chapter 8 on inheritance. So far, so good. It all makes sense that your class can inherit from any class above it. I am hoping it builds on chapter 7 as I still feel challenged in that regard. I am up to page 158 and hoping to do a lot more in this chapter, reading-wise, tomorrow.

No comments:

Post a Comment