Entries Tagged 'Uncategorized' ↓
October 7th, 2005 — Uncategorized
MockObjects is a concept that extends the xUnit testing framework. Whereas unit tests allow you to perform state-based testing, mock objects allow you to perform behavior-based testing. In other words, unit tests alone let you examine the state of the tested object before and after the test is performed. Mock objects are, by extension, more powerful, since they allow you to examine what the object is doing during the test. MockObjects, as a concept, is very cool and accords various benefits for test-driven development. Read more about unit testing, test-driven development, and mock objects, at Wikipedia.
MockObjects is a simple concept, yet many developers aren’t catching on. I personally have not found an appropriate analogy that effectively describes the concept. But just as object-oriented design should be intuitive and natural, so should the concept of MockObjects. So here’s a metaphor that I’ve come up with that might help in illustrating what mock objects can do. I’ll call it the “Donnie Brasco Metaphor,” and yes, it’s influenced by my personal love of mafia movies and shows. As a note, I’m talking about the abstract notion of using mock objects, and it applies to both static object mocking and dynamic object mocking.
Say you’re an FBI chief and you suspect a mobster is involved in illegal activity. So you stealthily follow the suspect around, see with whom he associates. You discover that he frequently visits a local corner joint on the east side of town, a joint notorious as a hangout for other suspected mafiosos. You have a feeling that inside that joint there is some discussion of illegal operations. However, the joint is exclusive, the shutters are closed, and you have no way to see what’s happening inside. Naturally, you set up a unit across the street with high-tech photographic equipment. You see who goes in and out of the joint. There is your suspect right there walking in empty handed, and walking out with a wad of cash. So you have some evidence that your suspect associates with known mobsters, and that some monetary transaction took place. But you lack direct evidence that he has done something illegal. You can’t just bring him in to the local office for questioning. He won’t admit anything. About the only way to establish any illicit doings is if you catch your suspect admitting to involvement in wrongdoing. And you can do that by sending in an undercover agent, someone who can act like a fellow mafioso. So you give your agent the right appearance and train him in mafioso mannerisms so that he can just blend in. Just like Donnie Brasco. Your agent finally manages to get himself a pass into the joint. You equip him with a hidden microphone and tape recorder. He acquaints himself with the suspect and eventually gets him to talk about his illegal activities. Once the agent splits the joint, you can examine the tape and assert the suspect’s involvement in some wrongdoing. Gotcha!
In case it’s not clear how this translates to testing with mock objects, let’s explain. A standard unit test examines the interface of the tested object, and lets us make assertions about the state of the object before and after the test. In most cases that’s good enough. In our case, the photographic equipment (the testing framework) lets us assert that the suspect (the tested object) walks in and out of (interfaces with) the joint (the real system). We can even assert that the suspect has nothing before he walks in but has something when he comes out. But when we want to test his behavior, which would establish his guilt, we send in an undercover agent. The undercover agent is the mock object. We set things up so that the suspect interacts with the agent. The agent dresses up and acts like a mafioso, so that he seems like any mafioso. In the software world, we test the behavior of an object by providing a mock implementation of a known interface, say a database, and let the tested object interact with our mock object. So instead of a real mafioso, the suspect interacts with an FBI agent equipped with an audio recorder, which allows you later on to make assertions about the behavior of the suspect during the time that he is inside the joint. This approach to testing also allows you to leave certain aspects of the target class private. Just as it’s implausible to kidnap the suspect, hypnotize him, and get him to talk out loud, it’s not always the best practice to make all methods of a class public just so you can test them. You can allow the object to interact privately with the system (e.g. make a database call from inside a private method), and instead mock a part of the system to see how it is being used by the object.
One final note. Many developers have difficulty with mock objects because they are unsure how to set up their tested object to use the mock object. If a class interacts with the database, it’s natural to connect to the database from within the class, say in the constructor. You can’t sneak into the joint and rig it with eavesdropping devices. Nor can you fool the suspect into walking into another exclusive joint that has been rigged. As a developer, you should use dependency injection, which lets your overall software architecture dictate how objects are initialized and used with each other. So just like our undercover agent convinces the mafia to allow him into the joint and ultimately record the suspect, your architecture should allow the mock object to be plugged in so that it too can interact with the tested object.
Some critics of unit testing point out that it forces an unnatural class design, in order that your objects can be tested. That’s a valid concern that unit testing alone does not address. Although test-driven development mostly produces elegant, well-designed code, it sometimes forces you to expose more of the interface (e.g. make private methods public) than you would like. However, mock objects further encourages design by contract, and produces code that conforms better to the system requirements.
October 6th, 2005 — Uncategorized
I finally caved in and added a new category to Sequelogue: Video Game Remakes. There are already quite a few movies based on video games. Either movies are getting dumber, or video games are getting more sophisticated. Today they already announced that Peter Jackson and his lovely wife Fran Walsh will be helming the production of the Halo video game remake.
September 22nd, 2005 — Uncategorized
I’m not going to write in prose, so don’t worry. I’m supposed to be in Houston tonight. Continental has not canceled the flight yet, but I ain’t going. Stacey’s PhD defense was scheduled for tomorrow, but that’s not happening. The professors left in anticipation of the storm. Many of my friends in Houston have already left for higher ground. Katrina has taught us all to be proactive. I’m usually pretty laid back and optimistic, but today I say: paranoia works!
And so, three months shy of my departure from Space City, I am proactively heartbroken about my beloved city. I admit, it wasn’t that beloved all the time, but it’s been great to me and to Stacey, we just started to appreciate it in the last year. And now, sitting there, flat as a pancake, more helpless than a fly caught in the cobwebs of a menacing beast, it calmly waits.
It hardly seems fair that Houston should be hit by such a terrible storm. Just as Katrina has exposed weaknesses in government and disgusting behavior by certain individuals on every level, Houston’s adoption of Katrina’s evacuees has only demonstrated utter compassion and unconditional kindness, a perfect example of Southern hospitality. It’s almost unconscionable that Houston should have to face such turmoil.
For some strange reason I feel extremely proud of Houston. I’ve been listening to live streaming audio from KTRH for the past two days, and the proactive regional response to Rita is just unbelievable. It seems as though some officials took a 3-week crash course in effective emergency management skills. Mayor Bill White, who I had the pleasure of meeting on a random bike ride, has really stepped up to the plate, and has really taken control of the situation. He’s a lot less helpless than Nagin, who should be sharing part of the blame for the post-Katrina fiasco.
But the storm will pass. There is no doubt Houston will endure. There will be some damage, but hey, Houston never had a shortage of ongoing construction projects. We’ll reschedule our visit, Stacey will get her PhD, I’ll get to ride with my buddies. Motorists will still not know how to drive, the bayous will still smell, they’ll never finish the Southwest Freeway I-610W interchange, and they will still serve frozen ‘ritas, although they might just call them something less evocative.
September 20th, 2005 — Uncategorized
I just don’t get the big fuss over John Roberts’ testimony, or lack thereof, at the judicial hearings. Everyone is raising their arms all of a sudden, rallying against his appointment to the Supreme Court. Because he refuses to share his opinion on these silly litmus issues.
Everyone wants to know if he’s opposed to gay marriage, where he stands on the death penalty, whether he watches CNN or Fox News, how many women he slept with, whether he believes O.J., what’s his favorite football team, if he wants to supersize it, on top or on bottom, venti or grande, boxers or briefs.
The problem here is not with Roberts. It is with us. We have become so jaded about the system that unless we know every single detail of everyone’s personal life and opinions, we cry “foul.” We can’t accept that the guy can just be a solid citizen with solid legal credentials. Because we can’t trust anyone. And no person is totally objective, we’re all influenced by our own biases.
But what purpose would it serve to know where he stands on abortion? He said he would uphold the rule of law, so he might as well be pro-choice, if that makes you happy. He clearly stated that he would judge a case based on its own merits, even if it disagrees with his personal opinion. Just say to yourself that John Roberts believes in whatever you want him to believe.
We have come to believe that once we know all the facts we’ll be able to make a sound judgment. But even if we do hear all the facts, we won’t immediately believe them anyhow. “This guy says he’s for gun control, but how can we really know?” In the end, we just want some affirmation that John Roberts is an honest man with no political agenda, and we falsely think that we’ll be satisfied when his opinions are revealed.
That’s why I say, STOP RIGHT NOW! Listen to this guy, look at his record, then decide whether or not you believe he will execute justice in an objective and fair manner.
August 24th, 2005 — Uncategorized
An astronomer is petitioning for the new C&T Calendar where the date falls on the same day of the week every year. This would have a vast economic impact, especially for calendar publishers. You would be able to just paint the calendar on the wall. The calendar would start on Sunday, January 1, 2006.
read more | digg story
August 3rd, 2005 — Uncategorized
Okay, 12 of the Top Diggs for This Year are stories about Digg itself or the Diggnation podcast. What’s the deal??? Digg.com is great, but c’mon. Enough with the Digg-Digg stories. When a new version of Digg comes out, or when the next episode of the Diggnation podcast is published, I think we’ll just figure it out, somehow.
read more | digg story
January 4th, 2005 — Uncategorized
You read it. It’s not misspelled. It’s my Webl (pronounced “Webble”). It’s the same as a Blog, but it’s cooler.
Whoever is the ad wizard who pretentiously coined the term “Blog” by shamefully purging the first two letters of the word “Weblog,” and what gave him or her the right? Did that ad warlock care to ask the then-simply-weblog community what it thinks should be the new term? Well, as a sign of protest (just because I like protesting simple irrelevant issues), I’m coining a new word that would mean the exact same thing but would sound swankier, and, frankly, cuter. I hereby name this journal entry a “Webl” and dub myself a “Webbler”! I am reattaching that congenial couplet, ‘we’, and instead bumping off that sinister, treacherous ‘og’ pair on the other end. Take that!
Much better. Blog has such a negative ring to it. It sounds like a bad concoction of “blah” and “smog” or “gog” or “bog.” It’s more of a shorthand to Balrog, Tolkien’s devil incarnate, than to Weblog. Webl, on the other hand, has a fresher, more pleasant, even more sophisticated intonation. It’s also similar to the now-popular and ever-present word, “Google.” You don’t just surf the net anymore. You google and you webl. I don’t even mind if the community prefers a less-obscure spelling of my new word, such as “webble.”
Now, I only need to get in touch with some patent lawyers I know…
December 14th, 2004 — Uncategorized
It got up to 83 degrees Fahrenheit here in Houston on Sunday. December 12. 83 degrees. Hell on earth. Well, it looks like hell is finally freezing over and they’re actually predicting temperatures below 32. At least for a spell of two or three days. That’s just wonderful. I like having seasons. And maybe I’ll stop spontaneously laughing out loud every time I see people white cotton masquerading as snow in Christmas decorations, because, you know, you can’t celebrate Christmas unless it’s cold.
December 13th, 2004 — Uncategorized
Junk mail has sunk to an all-time low. I am often bemused and befuddled by the lengths to which the geniuses behind these messages will go. Who’d have thought that African magistrates would contact me personally for promising business opportunities. Or sell me the latest m1r@cl3 dRuG$ for mere pennies? The perfect junk mail will fool you into giving away your credit card number and then leave you wondering for all eternity, like Andy Garcia in “Ocean’s 11″, how they managed to foil you! Drats! I came so close to sending over my bank account number and social security number to an “associate” in Zaire, when I finally realized he was just toying with me. He sent me an overly elaborate (yeah, of the Dr. Evil kind) CONFIDENTIAL email, we developed a certain kinship of trust (at least I thought so). But he just wanted me for my money.
But now I’m starting to get junk mail for cheap watches. Cheap watches??? Who would actually fall for that one? I mean, promise me a rolex, fine. Better yet, fool me into going to your website, thinking I’m looking for the latest youth cream, then find that you’re selling cheap watches. I might actually fall for it and say, “hmm, I really wanted to remove those wrinkles, but hey, a fake Swatch ain’t a bad alternative.” The cheap watch should be the hook, not the bait.
What is going on here, really? What does it tell us about the state of things, when junk mail, that vistage of the Online Revolution, that trusty little service that operates 24/7 like a… cheap watch, will sink to these levels? Are the Junk Mail Kings all out of ideas? Have they nothing better to sell? Or maybe they have concluded that all our email filters are set to catch sophisticated messages, while when we receive “Want a cheap watch?” in the subject line, the filters don’t know what to do and in a fit of panic dump the message in our inboxes.
Well, whatever the reason behind it, I hope the next trend is even more original (or fake, depending on how you see things). Frankly, while junk mail used to be annoying, it’s becoming quite entertaining.
November 23rd, 2004 — Uncategorized
I was baptized yesterday. I’ve ritually dunked myself in the cleansing waters and came out a new man. I have probably alienated friends and family, who have accepted me as someone who apparently I am not. I can try to convince them that I’m no different, but they all know better. Some will accuse me of joining a cult, others will just look on with pitiful, consoling eyes, as if to say, “we had so much hope for you.”
But that is the existence of a born-again Mac user. Good riddance, Microsoft Windows. Yes, I shelled out some big bucks and yesterday got me a shiny new Apple PowerBook. It took more than 2 months to convince Stacey that it would be a worthwhile investment. Apple marketing is quite effective at convincing you that when you buy an Apple product, you become part of this global community. So during this honeymoon period, while the naive air of euphoria persists, I’ll accept that whole-heartedly.
I even walked into a Starbucks and just sat there for 30 minutes, configuring my new toy, while others just looked on in envy (two people actually came by and complimented me on the notebook).
And now, as part of this community, I truly feel reborn, as if the PowerBook has actually bestowed on me a certain power I haven’t had before. The PowerBook has emPowered me to start a new page. I will now use it to become more responsible. I will use money software to maintain an active budget. I will use calendar software to manage my time better. I will write more software for residual income. I will manage digital media more effectively. And, of course, I will keep a more frequent journal log. And it’s all thanks to this PowerBook. Where would I be without you?
Now, I only wonder how many seasons will pass before I post another entry.