Blog Planet Wiki Why is this page pink?
Feed Feed It

The "Setter" and "Getter" gotcha.

Friday, July 30, 2004 11:01 AM

Alright, so there's this nice lady/girl that works here and she got reamed the other day cause I honestly don't think she understands object oriented stuff all that well. But how they got her was on this really easy concept. So the object oriented paradigm is all based around having a class for everything and/or anything. So please see my nicely written short and condensed example, now remember this is an example which an ideal condition, I'm sure there are better examples but this one came off the top of my head....so please just try to see what I'm saying and don't get caught up on the frivolous details.....
// Java Code Snippetclass AddressBookEntry{private string firstName;...public void setFirstName( string firstname ){this.firstName = firstname;}public string getFirstname( ){return this.firstName;}...}
// C# code snippetclass AddressBookEntry{private string firstName;...public string FirstName{set{this.firstName = value;}get{return this.firstName;}}...}
So as you can see here with something with a lot of data to manipulate in the class scope one has to make a decision, do you hide your data internally in the class by making all of your class member variables "private" and write what is called "setters", and "getters". Do you then decide not to sling a bunch of code...and just expose all of those fields to the world and make them "public"? Or depending on the language you're using which in our case is C++ do you decide to make a structure and pass the structure around? Historically, the reason for "setters" and "getters" is because some languages such as Java didn't implement structures. Like in C/C++, where you could define a data type with just fields of data of different types (i.e. int, long, double, char..etc..). So someone comming from the Java world such as our nice co-worker that got her ass chewed out and is now emerced in C++ land welcome back to a world of full control! See this is where I'd like to interject that I feel that "managed" code really dumbs people down and doesn't allow them to really understand what is going on with the machine, at the machine level. Problem is there are a ton of idiots out there, and there's this cool word called "productivity" that most managers love to see because they are pressured by deadlines. Drones!!! So back to our "setter" and "getter" dilema. So as you could imagine, all of the data that goes into a "AddressBookEntry" there's a lot so for every field in that entry (i.e. full name, address, telephone numbers, emails, web addresses..etc.). So in C++ one could do one of two things make a struct or just make a class and implement the copy constructor, assignment operator, and destructor because in our case we know there is going to be more than one AddressBookEntry, so we know this class is most likely going to reside in some sort of collection. So implementing those three member functions (methods) would allow our class to be used properly in a STL container such as a vector, map, or multimap.
/* AddressBookEntry.H or AddressBookEntry.hpp */#ifndef ADDRESSBOOKENTRY_H_#define ADDRESSBOOKENTRY_H_#include class AddressBookEntry {public:// constructorAddressBookEntry( void );// destructor~AddressBookEntry( void );// copy constructorAddressBookEntry( const AddressBookEntry & );// assignmentAddressBookEntry & operator=( const AddressBookEntry & );std::string first_name_;private:void swap( AddressBookEntry & ) throw();};
/* AddressBookEntry.C or AddressBookEntry.cpp */#include #include "AddressBookEntry.H"using namespace std;// ConstructorAddressBookEntry::AddressBookEntry( void ): first_name_( "" ){/* Left empty */}// DestructorAddressBookEntry::~AddressBookEntry( void ){/* Do class clean up here */}// Copy ConstructorAddressBookEntry::AddressBookEntry( const AddressBookEntry & info_to_copy ): first_name_( info_to_copy.first_name_ ){/* deliberately empty */}// Assignment OperatorAddressBookEntry & AddressBookEntry::operator=( const AddressBookEntry & right_hand_side){AddressBookEntry temp( right_hand_side );swap( temp );return *this;}// swap helper functionvoid AddressBookEntry::swap( AddressBookEntry & swapper ) throw(){// swap member variablesstring temp_first_name_ = swapper.first_name_;swapper.first_name_ = first_name_;first_name_ = temp_first_name_;return;}
I know there's more explaining to do, and I hope I can come back and finish this example up and explain my intentions and caveats!

Direction

Friday, July 30, 2004 10:55 AM

To find direction in anything is tough. I mean a person can have all of the tools in the world but if that person doesn't know jack about fixing cars then, they are just worthless. Now that really bites! Today is one of those days, where it just seemed really long and drawn out. I'm feeling frustrated on a number of fronts, and I just can't take it anymore. Perhaps it's because I need to hit the gym? I don't get it!!!! I think I need to go for a run tonight, and get this built up stuff out of my system.

Lego's for a child at heart??

Thursday, July 29, 2004 01:50 PM

Denise's Market

Tuesday, July 27, 2004 12:39 PM

Denise knows how to cook! Man this place was out of control. And the coolest part is all of the people from ebay work right across the street from this place. Funny thing is I didn't see a single male that worked at ebay, only cute blond females. I think I need to apply to ebay, and goto Whole Foods Market for lunch from now on.

Alcohol Boycott

Monday, July 26, 2004 06:04 PM

I think I'm going to boycott Alcohol usage.

Caffeine in the workplace

Monday, July 26, 2004 12:31 PM

So I've always been so interested as to why people at work, have to have that cup of coffee in the morning. I think I actually understand it now. It's to wake up. I've been trying to realize how do people just magically wake up, and show up in the morning to work like they've been awake for hours! I figured it out it's this drug called Caffeine, they should ban it! Just kidding, everyone would be too outraged with getting rid of our socially accepted drug that everyone is addicted to. But seriously this drug does wonders, and honestly I've been trying to not use that drug on a consistent basis cause I feel it's not good for me. But it does wonders!!! Woohoo!

Ontario Airport Again!

Sunday, July 25, 2004 08:11 PM

Well i'm back at Ontario airport freeloading on some wireless access point. Fun times. This weekend was decent. And well worth the effort to come down. I wonder what next weekend has in store. :-)

Coke or Pepsi?

Thursday, July 22, 2004 05:57 PM

Do you think Jesus would dig Coke or Pepsi?

I vote Coke.
So about two weeks ago I went to the shooting range and decided to keep one of my targets so I can decorate my cube!!!
I put it right next to my Hussien family portraits.

Palm HotSync over Bluetooth?

Thursday, July 22, 2004 04:40 PM

Yes it's true!!! I was at first highly doubtful, but I got it working!!!! Yes I can now really hotsync my a bluetooth equipped palm over bluetooth at work!!!! YES!!! I didn't think it would be possible, but after much fiddling I got it!!!! Now to get all of my calendar entries from outlook into the palm.

Women who puff cigars?

Wednesday, July 21, 2004 04:44 PM

I didn't know this kind existed. Quite interesting, and thanks to Drew for pointing that out.

Yes!!!!!

So little time

Wednesday, July 21, 2004 10:45 AM

So many things to do, so little time. I've found that more and more lately, there is less and less time, for my hobbies. I also found another marathon to run, and I think Daniel is going to run it with me. I think he should, so I could stick with him the entire time. Unfortunately I can't be down there to train with him daily, so i'm going to have to do that whole ad-hoc training thing. Which is kinda of shitty, but somewhat effective. So far from what I can tell my body has for the most part bounced back. My knees, and back are shapping up, and seem to be almost back to 100%. Which is great because my knees and back were highly questionable, and were seriously worrying me.

Really Tired today

Tuesday, July 20, 2004 11:08 AM

For some reason I feel really tired today. I had a great workout last night, and I actually felt good about the weight training portion of the workout. I've read numerous articles about how you should shock your muscles and all of this stuff. When I read it I'm like okay shock my muscles by changing up the different exercises. So I go in there and I change it up, yet feel nothing. But last night I tried a couple of different things and it worked!! The result is feeling tired right now! Life in general is decent. I keep not having the time to work on the things I want to work on as far as my side projects. But, spending my time at the gym is beneficial to me. I read an article somewhere that people who are active are less prone to depression, and there's some drug for depression that, when compared to working out, is about the same or exercising is better form of treatment for depression. Now granted, I think I'm not even close to being categorized as being "depressed", but I found those facts highly informational. So I know for a fact when I workout regularly that I feel a whole lot better, and balanced. So if my projects slide and take longer I'm totally willing to make that sacrifice. And figure out ways of working around it.

4th Generation iPod

Monday, July 19, 2004 06:15 PM

It took apple 4 generations to finally get this puppy right, which is entirely believable with their track record. But still a quite amazing device! Gotta love it.

I now, know where i'm going after work!! To the Apple Store Batman!

wiPod

Monday, July 19, 2004 05:36 PM

Found a cool website that has found out where all of the "free" wireless hotspots are at in the bay area. Check it out here. It's crazy how I find these cool things. So this same group of people have made a list you can put on your ipod so that you can check where the closest free hotspot is, if you happen to be anywhere in the bay area.

Reading is Good

Monday, July 19, 2004 11:44 AM

So I started messing around with Mono this weekend, and I was attempting to read in data from my Garmin Forerunner 201 which gets exported into XML. So I thought, hrmm....I remember how easy it was to read in and parse XML in C#, why don't I give Mono a whirl and see what it can do. Unfortunately, I came across some very very disturbing results. So when I would use the following.....XmlNode node = doc.SelectSingleNode( "Element" );orXmlNode node = doc.SelectNodes( "Element" );I would get some kind of nasty "object not set to an instance of a reference exception," and the stack trace would be pointing to a line that had one of the two of the above mentioned statements. So I tried a few different ways that I knew of how to see what is in the XmlNode, or XmlDocument object and narrowed it down to that in fact those methods weren't working at all!! So I then decided to finally read the documentation, and what do I find? "Method not implemented." Whoa, why didn't I read the documentation eariler? I have no idea, but I wasted a good amount of time on trying to hack around it. So funny.

Been working on Antislacker

Thursday, July 15, 2004 09:11 PM

Been working on Antislacker a lot more lately and beta testing a few web server applications to roll out on to the servers. Things have been going slow for that project. But slowly but surely things will get rolled out sooner or later.

Rejection

Tuesday, July 13, 2004 01:11 PM

Rejection in general is a pretty bad thing. But as with most negative things it's a motivational force in my life. Since I've started to play sports I have always been on the losing team. Even when things look like there's going to be an easy win, somehow the stars and celestial bodies (divine intervention?) all seem to pull for the other team, and I end up on the shit end of the stick. Sooner or later I just have to win. Hopefully more sooner than later. I think I need to redefine the rules so that every time I play I have to win.

The Most Exciting day of the week.

Monday, July 12, 2004 12:16 PM

I think Monday's are of course the most exciting day of the week. Started reading many of the books I have on C++ and getting back into that mode. I'd have to say that I enjoy the challenge and thinking that's required with "unmanaged" code. Microsoft has coined the terms "managed", and "unmanaged" code. Of course who ever decides to smoke some crack and develop using the .Net framework is writing "managed" code. We cavaliers that love to access hardware directly when we want to, and not worry about a layer of indirection/abstraction. "We" would be writing (condescending tone) "unmanaged" code. I'd like to call it writing code for the real world, and writing code for Venus. Because it is indeed worlds apart. Speaking of "managed" code, I actually got mono installed and have been busily getting used to all of the quarks of the development environment, which is entitled monodevelop. Mono is an effort to port the .NET Framework, a C# complier, and CLR to the linux platform. All I have to say is that this stuff is maturing fast, and is really going to catapult linux for the desktop in the right direction. And with M$ Longhorn getting delayed, and stripped of features it just gives Ximian Desktop more time to mature and pull ahead. And the funniest thing is that it's theoretically like M$ has not just shot themselves in their own foot, actually more like completely blew it off. All of the effort behind C#, CLR, and the .NET framework is completely M$ so imagine when Ximian pulls ahead and is using M$'s own technology??!!

Deadlines

Friday, July 09, 2004 01:22 PM

Deadlines...ugh!

Moore, is less?

Wednesday, July 07, 2004 05:11 PM

Check out this article.

Anticipation

Wednesday, July 07, 2004 11:12 AM

Nothing is worse than anticipation. It's gotta be one of the most time consuming things ever!

Another installment of funny pictures!

Tuesday, July 06, 2004 12:19 PM

Day Off!

Monday, July 05, 2004 01:31 PM

It is nice to have a day off. I've spent most of the day deep in thought. I arrived about an hour ago to find my secret spot completely full!!! I guess it's not a secret! I found another one. :-) So now I'm sitting out here, chillin' enjoying the air, and most importantly the sun. So now what do I do? I have no idea. Find out more later.

God Help Us!!!

Saturday, July 03, 2004 11:47 PM

What scares me the most about this country is how it's "middle america" whose votes really count!! Ugh the ploys that these two canidates go through just to win over middle america, it sucks but it's all to true!!! Come on, Kerry trap shooting? What is next...Bush, playing basketball with one of those late night basketball leagues that Clinton funded? That would make for some good pictures!

Unplugging is fun!

Saturday, July 03, 2004 09:08 PM

I'm off to my secret spot to relax and unwind. I feel this helps me re-charge for the week. I hope to just relax and take in some fresh outside air. And of course allow me to clear my thoughts and focus on something. There are of course so many thoughts that I just go with the one I happen to be thinking about for that moment. Well I hope after this session, I can clearly focus on each thought independently from the other.

No more traveling...

Saturday, July 03, 2004 12:24 PM

It seems that I'm going to be spending my 4th of July here, in Northern Calilfornia. Sucks cause I have no idea what to do, i'm sure i'll figure something out or, I'll be at the gym. Fun times up here!!! Fun, Fun!

I love Tennis

Friday, July 02, 2004 12:55 PM

Maria Sharapova, damn!!!

Space Ship One

Thursday, July 01, 2004 04:49 PM

Amazing photos of Space Ship One here.Space Ship One is the first Private Manned Mission to Space. Under the command of test pilot Mike Melvill, SpaceShipOne reached a record breaking altitude of 328,491 feet (approximately 62 miles or 100 km), making Melvill the first civilian to fly a spaceship out of the atmosphere and the first private pilot to earn astronaut wings.

Wow, Cassini is at Saturn!!

Thursday, July 01, 2004 11:01 AM

Wow!! Saturn, that was my favorite planet when I was in the first grade. Exciting!!

Jury Rigging Cable

Thursday, July 01, 2004 10:51 AM

Somehow when installing our neighbors cable on Monday, comcast disconnected our cable. So last night we devised a plan to reconnect our cable and give us at least our internet connection back. It's pretty funny, we have this white cable, coming out our front door and going all the way around our apartment and then connected into a three way splitter. So we just disconnected what we thought was our line, and hooked our new line in. Then about 5 minutes later we get a knock at the door. It was our neighbor asking us if comcast had just come by cause their cable isn't working. So then we found out that we and the person next to us share a single cable, but it's split, somewhere beneath the apartment, and hence that's where some idiot comcast rocket scientist somehow disconnected our apartment. So luckily we had another splitter, so in the end we've at least got internet back. Woohoo!