So today I had an interview at 5pm for what was probably the most exciting position to come across my plate in quite a while. A company called pagerduty, based out of California but has offices in Toronto, is looking for a software developer to join their team. Now two things grabbed me regarding this position.

First, the service that they provide is not one that relies on the populace giving it the facebook treatment, It has a reasonable business case, and one that if they had existed when I was doing sys admin work back in the mid 2000′s, would have been telling my CTO to get signed up with pronto to replace our incredibly flaky server monitoring software that we were using at the time. The second was that the core tech is written in Scala and Ruby, two languages that unlike PHP are on the way up in the programming world (especially Scala…stuff’s like Java of the late 90′s it’s growing that fast). As someone that has been looking to escape the PHP world since realizing that I’ve gone as high as I can in it (well short of joining Facebook or tumblr that is), I leaped at the chance to get on this rising star, and was very excited to hear that I had an interview scheduled. So I made sure that I got back to the house with time to spare. Everything settled, drink in hand, skype ready to go. I had been making sure that I knew enough about ruby and scala to not embarrass myself, doing tutorials, studying on-line texts and books that I had here at home on the subjects. Even coding up some small programs in the languages since I always found that the best way to learn something and make it stick in your head was to actually do it with your hands and mind.

So there I was, all ready to go. Skype call comes in, I click to receive, and I immediately find that my internet connection, which I thought was back up to the reliability that it should be, had decided tonight it was going to pitch a fit. Every third word was cutting out, which made conversation enjoyable for both sides. I kill off any processes that might be using network traffic and it gets marginally better, so I figure tough it out, answer the questions to the best that I can, clarify if it gets too garbled, and get through this. I give my standard run-down of what I’ve been up to as of late, he seems impressed of the work I’m attempting to do with the current project that I’m on. My confidence is rising, feeling good about this whole thing. I can do this, I think to myself. He then asks if we can start the technical part of the interview. Not a problem, I think to myself. I’ve been here countless times. I’m golden. Bring on your technical questions. Ask me to build a Class in Scala. Ask me how I’d lay out a form in Ruby. Inquire how I’d build a table schema with linked foreign keys. I’m ready to go!

So the first question arrives. “Parse a Binary Tree for a certain value, and return if it exists or not”. Piece of cake….wait….. what’s a Binary tree? In that moment, I heard a clicking noise, like you’d hear with old zip drives. The signal that after being taxed since 7am this morning, your brain saying, “I’m done”.

You can guess how well things went after that

My interviewer had the patient of a saint, trying to explain what exactly he wanted me to attempt, through a wireless connection that had both of us sounding like someone was flicking the mute button at speeds that rivalled couch surfers on coke, but it was to no avail. Every attempt to access my brain resulted  in HAL replying “I’m sorry, we’re closed. Please try again later”. Every word came across as if it was said in Esparanto. It was like my mind had been thrown into reverse while doing a hundred and ten on the highway. A lockout of such infinite proportions that I was glad that the video feed had been turned off a while back, as I’m sure the visage that I would have presented would have had Cletus going “You look just like my slow cousin Ted”. And after twenty minutes, and letting my tortured interviewer free from this brutal episode (the only thing my brain seemed to register was his growing frustration, and who could blame him?), I sat in my chair, staring at the screen, not knowing what train had hit me. Only knowing that my confidence, and my prospects for this position, were as splattered as a Northern Ontario moose across the grill. I just kept thinking over and over again, of all the times that I’d get hit with something out of a first year Computer Science 101 book, it had to be with a job that I actually found exciting and interesting.

Now in the few times that this has happened before, I’ve learned in my travels that doing anything other then learning from your mistakes and moving on is a sure-fire way to sink into a pit of self-pity and have your self-confidence shot to hell for….well a long time. Yet that night, and into the next morning I couldn’t “move on” per say. I talked to friends of mine in the industry about it, with each conversation having a “you didn’t know what a Binary Tree was?” in an incredulous tone that only helped to reinforce that even with years of experience, I wasn’t as knowledgeable as a first year, wet behind the ears, college student. It really helped to reinforce the stigma that PHP developers don’t know a damn thing about programming (something I get tossed at me, albeit playfully often), and put a big “you’ve wasted your life!” exclamation mark on my whole career. For anyone reading that’s ever experienced such a feeling, I think you’ll agree it’s not a pleasant feeling at all.

Normally I’d get home, sit on the porch and have a beer, or go for a drive to clear my head. However that night, I decided to do something different. I decided to grab the bull by the horns, and told myself that I wasn’t getting out of my chair until I not only knew just what a BTree was, but could give a working example of such functionality in code that someone could call if they so chose. I figured no sense having a pity party where it’s going to get me nowhere, if I don’t know something, learn it and learn it well so when you need to know it next time, you can nail it like a pro. After five hours of researching, coding, testing, coding some more, and finally committing it to github, I do believe I nailed it. For those that may be interested, here’s the code.

function searchBinaryTreeArray($binaryTreeArray, $value, $parentKey = 0) {
if ($parentKey === 0) {
$parentKey = implode(array_keys($binaryTreeArray));
}

$childKeys = array_keys($binaryTreeArray[$parentKey]);

$result = false;

if ($value === $parentKey) {
$result = true;
} else {
if ($value < $parentKey) {
if (is_array($binaryTreeArray[$parentKey][$childKeys[0]])) {
$result = searchBinaryTreeArray($binaryTreeArray[$parentKey], $value, $childKeys[0]);
} else if ($value === $binaryTreeArray[$parentKey][$childKeys[0]]) {
$result = true;
}
}

if ($value > $parentKey) {
if (is_array($binaryTreeArray[$parentKey][$childKeys[1]])) {
$result = searchBinaryTreeArray($binaryTreeArray[$parentKey], $value, $childKeys[1]);
} else if ($value === $binaryTreeArray[$parentKey][$childKeys[1]]) {
$result = true;
}
}
}

return $result;
}

or pull it down from github

As I write this blog post late on a Friday night, when I would have expected to be at the local watering hole, a thought of anyone that reads this wondering why I even bothered to do this came up. I can’t think of any time that you’d ever use this when developing web apps, especially since both arrays and SQL databases would take care of doing storage and searches for you and in more efficient ways then a simple Binary search. In the end though, it wasn’t the point. One of the things that I absolutely loathe is being set back by not knowing something, especially something that I feel I should know being in this profession. Having knowledge that I didn’t know something so rudimentary is like a sliver in your foot, always reminding you its there with each step. Also I have a tendency to get comfortable, be it with skills, work environments, or life in general, and something like this has in the past been pretty hard hitting. Forcing myself to power through and use my willpower to make sure that I will have this experience become a positive for me in the long run? it’s the way to go, and as a side bonus? It makes you feel good about yourself, which after such an event, is just what your ego needs.

Now if you’ll excuse me, I’m off to the local watering hole to celebrate, and listen to a few audio books on programming. Figure it’s a half hour drive, why not be productive even more so?