Friday, August 31, 2007

Why programming sucks



This is a screenshot of something hideously funny we did to Razvan (not his real name) during fourth year. This is how geeks get their kicks. And now that it's about five years later, the statute of limitations has expired so I can freely admit to having done this. One day Razvan asks me for a hashtable implementation. Sure, I said. Have this hashtable, I said. While I was preparing this hashtable for Razvan, Brad (a friend in CS with a decent sense of humor) and I hit upon a brilliant idea. This picture is kind of blurry but it shows what we did. Look very closely at the second line. Can you make it out? It says:
#define if while
This clandestine directive, inserted into the code we gave Razvan, was the source (pun not intended) of a huge amount of grief. Programmers will immediately recognize the nightmare world into which we have plunged this unwitting little hashtable. But the rest of you must be wondering, what does this mean?

Well, let's start with the basics of programming. Flow control is how you get the computer to do things conditionally. This is what the if keyword does. Think of it like this.
if (raining) {
bring(umbrella);
}
Unless you're abysmally retarded you probably got the gist of that. Loops are similar to flow control and work like this.
while (money > 0) {
spend(money);
}
Easy, right? Now the #define keyword. This is the same as doing a find-and-replace in a word processor. Check it out, y'all. If I put the lines
#define if while
if (raining) {
bring(umbrella);
}
in a program, the #define line tells the computer, "any time you see 'if,' replace it with a 'while.' " And the computer will do that because computers are stupid. So what you've essentially written above is
while (raining) {
bring(umbrella);
}
which is utter nonsense: you're going to keep bringing more and more umbrellas with you until die of umbrella poisoning. You're just going to keep stocking up on umbrellas until it stops raining and accomplish nothing else.

Well basically, this kind of logical fallacy is exactly what we introduced in Razvan's shiny new hashtable. Any time the program we gave him tried to do an if statement, it would spin off into an infinite loop that would just keep chewing up processor power until you had to restart Windows 2000. And all because of that one line. If you were to remove that one line, it would work perfectly. Absolutely perfectly. And that is why it was so funny. It's also incredibly hard to detect, because when you debug you never expect anyone to put in a bug intentionally. Poor Razvan.

Of course, this implementation, as it is, doesn't work completely. Anything with an else clause won't compile (although it will throw up some very confusing error messages). You'd have to add the line
#define else if(0)
or something in order to cover all your bases and get all programs to compile. Or you could do
#define if(x) if(!(x))
(the expansion is not recursive). I'll leave it up to you to determine what kind of havoc that wreaks. Non-programmers:
!x
means “not x,” or the boolean negation of x.

This is just one example of things geeks do instead of talking to girls.

Monday, August 27, 2007

HDR and Mount Rainier

I'm really tired from hiking this weekend guys, so those photos will have to wait until tomorrow. Sorry!

In the meantime, check out these HDR pics from our trip. HDR stand for high dynamic range, and it's a technique that creates some pretty surreal-looking photographs. I tried it for the first time at Rainier and got mixed results. Partly due to my own unfamiliarity with the technique and partly because I didn't have a tripod. Nevertheless, here are the best HDR pics from that weekend!


Sunshine Visitor Center


Shadow Lake

I promise to have the rest of the photos up soon. Boy am I tired.

EDIT: The photos are up. See below. And I'm still tired.

Mount Rainier


Friday, August 24, 2007

Old school

One of the most amazing Zangief players you'll ever meet.



Reflection

Summer was such a busy season! Taking the time to recap everything would require many blog posts. So instead I'll squeeze everything into a photoessay so as to keep you entertained with thousands of virtual words. Don't worry, I'll still have some real words so that you're not too entertained.



Vancouver: The final frontier. Despite Adrian's insistence on showing me the intersection of Main and Hastings, Vancouver is a great, relaxing city with a lot of natural beauty, when it's sunny. It's also full of the tastiest Chinese food (and girls!) I've ever seen.



San Francisco: Under the guise of an Apple conference, I went in June. What a refreshing perspective it gave me! Must have been the sea breeze.



Calgary: Despite the, um, colorful wildlife (see picture), it was a fun, quaint town with a lot of natural beauty. Good friends, good food, great steak!



Around Washington: The pic is from Snoquamie Falls. There are so many places to explore. This was one of the first things we did. And the most unexpected part: fresh oysters, $10 for two dozen!



ECC/Genesis: A walk on the spiritual side of life. I felt like we learned a lot about God and faith and gained a deeper understanding of Christianity. Or maybe I just had a lot to learn.



Safeco Field: What summer would be complete without seeing the Jays lose? At least the hot dogs were good.



Boeing: The launch of the 787, which was apparently completely hollow inside. Thanks to Mark for the invitation. I managed to get some great shots because they mistook me for a press photographer and waved me to the front of the line. Asian guy with a camera? Let him through!



Ontario: We went to the beach, hung out, played some Wii. Just like old times. What can I say? Absence really does make the heart go yonder.



Skydiving: Yeah, I know I just posted about it, but I jumped out of a plane so I think I deserve to post about it twice!



And just last weekend, Tiger Mountain. Not as steep or as long as Banff. When we got to the top, the birds ate out of our hands like a nerdy white guy picking up in Tokyo.