Wednesday, December 10, 2008

Week 1, Day 6

Hey, something completely new to me! Score. Finally I get into some meat.

Today's "Class"
Today was all about Classes and objects.

I have never done object oriented programming (in the strictest sense at least). This chapter really made the five slow days behind it pay off (well... start to pay off). I actually learned some new concepts and my brain is busy absorbing the new information and what it means for my code in other languages. So, I am pretty happy obviously.

Classes are the new "types" of variables the book talked about in the past. I think this is a misnomer personally. You still are restricted to the limitations of the pre-existing variable types in C++. I was hoping (and still hold out some hope that this is included in C++) that you could have an array, or even better, a hash. How I have become so dependent on arrays and hashes.... PHP has spoiled me I tell you! So, while not able to create a new type of variable in the sense I wanted, classes are still very useful. Classes (and the individual objects of that class) are organized groups of data and functions. Here is a for instance:

Class: Car
Properties: Wheel Size, transmission speed, engine size, gas tank size, number of passengers, ...
Functions: Throttle engine, shift gear up, shift gear down, engage brakes, open door, ....

With all of the variables set up and the functions defined, you could easily create an instance of a "Car" by typing:
Car mySubaruImpreza;

Or, if you have the class constructor built, you could assign all of the specifications of the car right when you create it.

Honestly, writing a review of the chapter today would be like typing the entire thing. I'm not going to do that. So, instead, buy a book, check one out from the library, google C++ Classes, or whatever you usually do. This is one of those things you should learn from something more substantial than a blog designed to review one person's efforts toward learning how to program on Linux.

Summary and Workshop
The exercises again made me think. Probably because the whole Class thing is fairly new to me. The closest thing I have come to this is doing some OOP stuff in JavaScript. Oddly enough, it is actually pretty similar... but C++ takes it above and beyond the little I learned in JavaScript.
I made a few mistakes in my code as I worked on the proposed problem. I'm glad too... because every bug I made taught me a little about Class declarations and definitions that I had apparently not paid attention to during the chapter.

No comments: