Latest Publications

HashTable vs Dictionary<>

I’ve been using a Hashtable in my DBObject because, well, I’ve never seen any problems with it. But some people on the internet seem to hate the HashTable (something I’ve never understood.) So I decided to run my own test.

I ran two tests, one with a HashTable that uses a string as the Key vs a Dictionary<string, int> and another with the same HashTable vs Dictionary<string, object>. It seemed like the Dictionary with an object would be a better comparison because I need to store objects, not just ints.

Here is the first result:

hashtable times 1
(more…)

  • Share/Bookmark

Refactoring DBObject, Part 3

I think it’s time for a demonstration. In this example I show two ways you can use joined tables within the object. I also so why the KeyPath would be a useful addition to the object.

In User.BirthDate I’m joining two columns from the table users_info directly into the User object. There are problems with this. For example I have to change the table and index column. I’d also have to change the column names if I did and update (because birth_date and death_date don’t exist in the users table.) Over all the BirthDate method is sloppy and error prone.
The DeathDate creates a new DBObject and works off that. This is a cleaner apporach, I just have to remember to update when I update the User object. This also shows why KeyPath would be a nice addition. (DateTime)((DBObject)valueForKey("user_info")).valueForKey("column_death_date") isn’t nearly as nice as something like (DateTime)valueForKey("user_info.column_death_date")
(more…)

  • Share/Bookmark

Refactoring DBObject, Part 2

Note: I really shouldn’t call this refactoring because it’s an api change.

My SetProperty() and GetProperty() methods are really just my weak attempt to add KVC (Key Value Coding) to the DBObject. This is something built in to objective-c. So I want to rename these methods to reflect their true nature. (The word Property was confusing anyway.) It would also be nice if we could get the values via the object indexer. Although we don’t want to rely on this because the child class might wish to override it.

So SetProperty(string property, object value); will become setValueForKey(string key, object value);

and GetProperty(string property, object default); will now become valueforKey(string key);

and the overrideable valueForUndefinedKey(string key); which will be called when they key doesn’t exist.
(more…)

  • Share/Bookmark

Refactoring DBObject

DBObject has come a long way recently and there is a lot of duplicated code. So I think now is a good time to refactor.

Let’s start with the most obvious items. There are only 11 methods in the DBObject, 7 of them take string connection, 4 take string index_column, and another 4 take string table. These values should almost always be the same for the entire life of the object. It would make secence to define these somewhere and just use them instead of having to constantly pass them.

But where should we define them? I can see  3 options. Using properties on the object that the child can set. Using SetProperty and having a special key for these items. Or forcing the child to implement methods that return the correct value.

I’m not a big fan of the third option. It just seems like too much work for the developer using the object. It would be the most flexible option, but I’m not so sure that we need that kind of flexibility. I like the second option, except it provides the possibility that the child could accidentally changes these values. If we say the table name is stored as _table_name_ then there is always the possibility that the developer could try to put something else in that value. This would cause strange bugs in the object. The only thing I don’t like with the first option is that it doesn’t use the SetProperty system. You have to define these values via some other system rather than the one used for everything else.

I think for now, These  properties should use the current SetProperty system. This will keep things consistent.  So in addition to the column_ properties, there will also be _table_name_, _index_column_, and _connection_string_. We can have the methods verify these properties exist before running any method that uses them.
(more…)

  • Share/Bookmark

Checking if record/object already exists.

Last time I said it would be nice to know if the record already exists in the database. When you want a one-to-many relationship, you don’t want to accidentally add the same record more than once. If an object is made that has the exact same values as another record, we shouldn’t add it, but simply change the index to point to the correct record. Then again, you might want to allow such duplicates (like a history log.)

So today I created a new method for DBObject called doesExist. It simply returns true or false if the object already exists in the database. One thing you have to watch out for in MySQL is checking for NULL. You can’t simply do WHERE column=NULL It won’t work. You have to call it as WHERE column IS NULL
(more…)

  • Share/Bookmark

DBObject with Self Updating.

I’ve added self updating and Insert to the DBObject. I’ve also changed the naming of the columns it pulls from the database. Each column property now starts with “column_”.
(more…)

  • Share/Bookmark

Objective-C makes C# look funny.

I’ve been learning Objective-C (and Cocoa) in my spare time and I’ve recently been playing around with CoreData. It does a lot of the work for you and helps you build full featured applications quickly. And I was wondering where this kind of technology is when I do windows programming. Granted I’ve been focused on web stuff for the last few years, so maybe it exists. When I opened Visual Studio this morning I was greeted by a post of an undo/redo framework. CoreData gives you this functionality for free, you don’t have do do anything, it just works. (If you’re not using CoreData then Cocoa has a very easy to use framework for undo/redo.)

I just found this funny.

  • Share/Bookmark

39. Letters from inside the story.

Dear Heather,

I’m sorry. I’ve been cheating on you. I know it’s too late for apologies and I know there is nothing I can say to make you come back to me. You shouldn’t. You need to be with a great guy who can take care of you and be loyal. I’m not that guy. I love you more than anything in the world. I’d give up anything for you. But that doesn’t change the fact that I cheated. I just want you to know that I’m sorry and I never wanted you to find out.

I don’t know why I did it. Why does a guy give up the girl he loves for some cheap, dirty fling? When he knows he’s going to regret it. When it tears at his heart to look at your smiling face afterwords. And it does. Every time I cheated on you I woke up the next morning and just cried. Cried and prayed to god that you’d never find out, because I love you and I never wanted to lose you.

If it makes any difference to you, I left her. Actually I left her sitting alone in the middle of a field. I never want to see her again, and after what I did to her, she’ll never want to see me. She isn’t all that hot or anything. She’s kind of plain looking. Her hair is always pulled back and it stretches out her forehead. It’s just that she was there.

It was innocent at first. You never wanted to go to my friends parties. God knows I’d asked you. It’s like, if you would’ve been there, none of this would have happened in the first place. But no, you had to study or wake up early or something. This party was in this rundown house in the middle of downtown. I wouldn’t be surprised if it was condemned. We where all smoking pot and this girl sat down next to me. It was all innocent, I even told her about you! She told me about this guy she’d been dating since high-school. She said she’d never been with anyone else. He didn’t know she was here. Everything was happing all at once and we where sitting on this old couch that smelled like a dumpster, and she kissed me.

The next time I went to a party she was there again. I talked about you and she did it again. She kissed me. I tried to push her off. I was upset about last time. I told her and she pushed me down. She just pushed me the fuck down like I was some sort of rag doll and got on top of me. She started kissing my neck and pulling up my shirt. I tried to stop her, but she said if I resisted she’d scratch me so you’d know. See I didn’t have a choice, she basically raped me. I wouldn’t have done it otherwise.

Why didn’t I tell you? Who the fuck is going to believe me? My friends didn’t and they watched her do it! I just wanted it to be over and to be with you again. And we were, we were so happy together. Sure we had a couple of fights, but everyone does.

And then, I dunno. We fought about something or another as I was leaving for a party. I dunno, I was just pissed off. I didn’t care what happened. At the party I smoked like two bowls. I was just smoking and bitching and this fucking girl shows up again. She was upstairs the whole time I was down there and she must’ve heard me talking about you because she comes down and tells me to dump you. And I was like no, I love her. And she was just like then why’d you fuck me?

Fuck, I don’t know. I don’t know why I do half the stupid shit I do. And so we started fucking, like every weekend. It became, I dunno, almost normal, as crazy as that sounds. It’s like I had my perfect sweet beautiful girl all week long, and then friday night I had this nasty dirty whore. The kind of girl that goes ass to mouth while my friends cheer us on. It was exotic. And the whole time I knew I could just leave and come back to my perfect girl. The girl I wanted to spend the rest of my life with.

If I could do it all over again, I don’t know what I’d do. I hate myself for losing you. I really do love you. With all my heart I love you. I’d buy you the moon if it would make everything better. But I know it won’t. You’ll never come back to me and you shouldn’t. I wouldn’t if I were you. For whatever it’s worth, there’s a scar on my heart. Losing you was the biggest mistake I could’ve made, I’ll always love you.

©Chris Richards 2009
  • Share/Bookmark

14. No ideas, but in things

A drop of water hits a distant pool. Lola freezes mid-step. Her hand snakes around her hip resting on the hilt. Another drop of water echos. She relaxes her grip and takes a tentative step, feeling the hard earth though her thin leather shoes. The drop echos and the sound of shuffling of footsteps follow. Lola finds a boulder along the cave wall and kneels behind it. She drops a rucksack and her nose wrinkles from the dust. Rocks grind against each other further down the cave. Lola flips though a stack of colored papers in her rucksack. Steady rhythmic breathing fills the area. Grabbing a bright orange and red paper, she jumps out and flashes it. A white outline of a printed flame catches the light. She closes her eyes to the heat. A dagger clangs on the rocky floor and a charred corpse falls on top of it. The paper turns to ashes. Her hand smothers screaming faces carved into bone handle as she draws her sword.

She picks up a small stone with her free hand and follows the cave to a bend. She puts the sword shoulder height and throws the rock around the corner. A drop of water echos. A short shadow moves around the bend and she thrusts. Blood jets over the cave wall. A body falls, the dagger clanging next to her feet. Around the bend a stalactite drips another drop of water into the puddle bellow it. Flipping the body over, Lola searches the pockets. She pulls out a dull iron key.

Trevor pushes back from the keyboard. Orange fingerprints stain the left side. He brushes Cheeto dust off his belly and stands up. He bumps in to the desk sending Mountain Dew cans across the floor. He kicks them as he walks into the kitchen.

©Chris Richards 2009
  • Share/Bookmark

67. Travesty

Amy Wong brushed the soft earth off as she crossed back into the room. She felt the ground with her bare feet and pushed away small clumps of broken rock. The room was empty now; a few torches illuminated its smooth surfaces. Amy wondered why the professor ever built these tunnels in the first place. She walked as far into the room as she could with one hand still on the hole Zoidberg had dug for her escape. Working up some courage, she called out. “Zoidberg, where are you?”

A loud roar echoed from the darkened hallway on the other side of the room.  Amy pulled herself back though the hole and watched. Zoidberg came out with Leela in his arms.

He laid her out in the middle of the floor, under the torch light. Her clothes covered in perfectly round holes of the same size. Red hickeys covered her bare skin in the same pattern. Zoidberg looked in each eye checking for dilation or brain trauma. He held his left claw up, “How many claws do you see?”

Leela’s eyes focused on him. “You saved my life.” She reached out and grabbed his free claw. He screamed in pain. Leela quickly let go and looked at his claw. It was cracked down the side. “Oh my gosh, you’re hurt.” She tried to sit up.

He pushed her back down. “You can’t move, I think your rib is broken.” He stuck his good claw though the holes in her shirt and cut the rest of the fabric away. He pressed slightly around her ribs. She flinched in pain.

Amy charged into the room. “Back off Leela, Zoidberg is saving me.”

Zoidberg turned to face her. “What are you still doing here? I told you to escape.”

She threw her arms around him. “I can’t leave you, not after you saved my life.” She forced her lips to his mouth. He fought her for a second and then gave in, his tentacles wrapping around her head. She stroked the quivering fin on the top of his head.

Leela pounded her boot on Amy’s bare foot. Amy yelled in pain and jumped around holding her injured toes.

“Broken ribs here.” Leela said.

Amy cursed in Chinese. “He’s saving me.”

“Ladies,” Zoidberg said. “I’m a doctor, I save everyone.”

Glowing blue eyes came out of the darkened hallway. Zoidberg barely registered it when the giant octopus reached out and wrapped a tentacle around him. He fell on his broken claw. It dragged him along the hard floor, his exoskeleton breaking and leaving red pieces along the floor.

“Hurry, run” Zoidberg yelled as the octopus held him upside down. Another tentacle came out and suckered onto his broken claw.  He screamed in pain as the claw ripped free of his arm.

Amy struggled trying to lift Leela. She managed to stand her up. Leela limped with her as they made it to the hole. The octopus swung Zoidberg in the air. “You have to make it out.” Amy cried. “I need you. I need to be saved.”

They ran though the hole and disappeared.

The octopus stopped swinging Zoidberg and watched the hole for a minute. When no one reappeared the octopus took Zoidberg into the darkened hallway. He held Zoidberg steady so he wouldn’t hit the walls as they turned corners. Eventually they came to a large cavern with light filtering down and reflecting off a large pool of water. The octopus sat Zoidberg down on a bed of broken coral. “Are you ok?”

Zoidberg held his head and sat up. He swallowed a blue pill from his pocket. “I’m going to need a new shell after this,” he smiled at the octopus. “You did good Fred. Amy’s totally fallen for me.”

“Are you sure? I didn’t mean to pull off your claw like that.”

Zoidberg looked at the stump. The end was starting to bubble. “Don’t worry, it will grow back.”

© Chris Richards 2009
  • Share/Bookmark