All the cool kids are doing it:
Your results:
You are Dr. Doom
|
Blessed with smarts and power but burdened by vanity.![]() |
Sun 31 Dec 2006
All the cool kids are doing it:
Your results:
You are Dr. Doom
|
Blessed with smarts and power but burdened by vanity.![]() |
Thu 21 Dec 2006
As the first and perhaps last act on my MySpace account, I have participated in the Ze Frank MySpace Adoption Extravaganza!
Mon 18 Dec 2006
For anyone as annoyed as I am about 1.month.from_now being inaccurate, lean on your favorite Rails team member to get this patch accepted.
Sat 16 Dec 2006
This weekend is the weekend I have to do Christmas with my mom. In deciding whether to take the train or to fly, I eventually decided to fly since it was just barely cheap enough to make it worth it to me for the amount of time I expected to be in Bakersfield, which was about 1.5 days. I, like probably many people, still think of buying an airline ticket as a guarantee of travel. Not that they guarantee that you’ll get there on time, but that if something does go wrong they will compensate you. Most people choose their flight times for good reasons, either because they have a connection, because they have a limited time to spend where they’re going, etc. So when I buy a ticket, I think of going at a different time as something that should be compensated. That, apparently, is where United and I disagree. My flight was cancelled due to mechanical problems, but not before they let us board, did the whole pre-flight routine, then told us to get off and wait, which we did for about 30 minutes before they told us that it was cancelled.
To be fair, I suspect United is not alone in this, and that most domestic airlines including United share Delta’s motto according to Ze Frank: “Go Fuck Yourself”. If I were to value my time according to how much I get paid at work, and take into account that my taxi would be unnecessary later in the day since I can take BART, I’d say United owes me about $150 bucks for wasting my time, which is incidentally what they wanted me to pay them to change my return flight to a day later since I’ll now be spending less than 24 hours in Bakersfield.
I propose that United and the other airlines get together to dispel this myth of timely, courteous, and guaranteed travel with a marketing campaign designed to educate consumers about the realities of flying in the United States. Some of their key slogans might be:
Something along those lines would really be a major step in the direction toward truth in advertising.
Sat 16 Dec 2006
To be precise, her character in Lost in Translation is hot. She’s attractive, she’s witty, she’s a mellow offset to the crazies her husband hangs out with, she graduated from Yale, and she wears conservative clothing that still compliments her body quite well. On top of that I know the feeling of being a bit lost in unfamiliar territory. My ideal woman.
Fri 15 Dec 2006
When coding there are many guidelines you might opt to follow, such as Convention Over Configuration, the Principle of Least Surprise, and others, all intended to prevent you from falling into certain pitfalls. One such pitfall is one that I myself often fall victim to, and involves spreading the knowledge of the internal workings of one component to several others. That is, if A, B, and C all know how D works, then there’s really little point in grouping functionality inside D in the first place. Avoiding this pitfall is what the Law of Demeter tells us to do. To quote the Wikipedia article:
When applied to object-oriented programs, the Law of Demeter can be more precisely called the “Law of Demeter for Functions/Methods” (LoD-F). In this case, an object A can request a service (call a method) of an object instance B, but object A cannot “reach through” object B to access yet another object to request its services. Doing so would mean that object A implicitly requires greater knowledge of object B’s internal structure. Instead, B’s class should be modified if necessary so that object A can simply make the request directly of object B, and then let object B propagate the request to any relevant subcomponents. If the law is followed, only object B knows its internal structure.
Unfortunately this is done all the time in Rails, partly because they make it so darn easy to access associations and their associations:
Looks innocent enough. But what happens when we sprinkle this around our codebase in a variety of forms, and then without warning the requirements change and all of a sudden the mailing address is now attached to the user rather than the profile. This will require going through all your code that might look for the mailing address and updating it. You’d better pray you have near 100% test coverage.
The unpredictable and despotic need for change that creeps into every project is the reason you should care about the Law of Demeter, also called the Principle of Least Knowledge. But what do we do about it? The Wikipedia excerpt above makes it pretty clear that we should define mailing_address on Shipment and User:
Okay, fine. Not the prettiest, but it does help us with refactoring. You may have noticed a problem with both the old code and the new version: what if one of the associations is nil? We’ll get a big fat NoMethodError of course! Let’s fix that:
Getting kinda ugly, but it works better now. Both refactoring and nil problems are taken care of. Now that we’ve got that, we can rip it out. A while back Rails got a method called delegate that’ll let us do just this type of thing, providing both the refactoring safety and nil safety. Using this method we can change our code to this:
Isn’t that cool? Now it’s nice and semantic, safe, and refactorable!
Fri 8 Dec 2006
Some people are so silly. I just can’t get this image out of my head.
Wed 6 Dec 2006
While it’s nothing major, Rails recently got the ability to render JSON a little more easily:
This sets the content type to “application/json” and renders whatever text passed. But wait! There’s more! You can also start implementing Yahoo!-esque REST web services with JS callbacks like so:
You might wonder why I’d bother blogging about this. It’s because this marks my 5th patch into Rails (well, maybe 4.5 since it was originally posted by someone else and I updated it with tests). w00t!