Sunday, June 10, 2012

Why call it "Limit Equals One"?

When I first started learning how to program I felt like I would never be able to create things that everyone else around me seemed to be working on. Over time I started gaining experience and at the moment I still think of myself as novice at best. But I feel like I should chronicle my problems and solutions as well as my outlook on current events in the technology industry so I can look back on how I currently think and view my change over time.

The "Limit Equals One" problem is an inside joke of my first major oversight while working on a personal project. During my first semester of Python at CofC I was playing around with Google App Engine (a Platform as a Service computing architecture) and the Yelp API (use Yelp's data to search for restaurants) to be able to aggregate date ideas for people (me). After finally getting used to printing data on the screen, and grabbing data from Yelp I finally put two and two together to make seven! ... It didn't work. GAE and Yelp did not like talking like it did when it was just a local API call. After playing with the code enough I finally got it to spit out a single location when I called out to Yelp. Normally the Yelp response to a query though was to return 20 locations from a query. I could not figure out why it wasn't working as intended especially because it would return 20 locations when I did the query from a local machine.

During the first meeting of SHDH (SuperHappyDevHouse-Charleston) I found my problem. James (the person I dragged with me to the event) kept asking me the entire week I was frustrated with the problems if he could see the code. I denied him because it was actually a small part of a bigger project that wasn't my idea, and I didn't want to disclose information about it. But, during SHDH he finally got through and I showed him my code. "What is this Limit=1 mean?" he asked. I looked at the code and thought about it for a minute and remembered what happened. Originally when I got data from Yelp it was in JSON format, and I have never decoded something like it before, so in the call to Yelp I set a limit to only return one object so I can learn how to parse it. In my joy of parsing everything correctly and changing the code that ran locally I never realized that I still had the limit on the code in GAE. The entire time I thought there was a problem with the way I setup my system in GAE, when in reality the problem was a single line of code that just needed to be changed.

After changing the line of code and pushing it up to GAE it ran fine. James sat there smug as hell and said "I'll never let this down. You know that right? When you are helping someone and they get depressed for not getting it, I'm going to tell them about this so they know that everyone does something stupid at one point or another." And to this day he still asks me if the problem I'm currently trying to debug is a "Limit equals one" problem. He even admits that he had something that came "close" to it.

The few things I can say I learned from this are:

1. Always work on something else if you have been looking at the problem for a while.

I figure that looking at it with fresh eyes and a clear mind will be better then looking at it thinking you know something works the way it is supposed to.

2. Ask for help (or at least accept it when someone really wants to)

My problem was one that I still have today. I think that if I hit my head against the wall enough I can solve every problem. And while this may be true it might be better to fail a few times then ask for a better way then to fail a hundred and still working for a solution. While I do agree that failures will teach you more then right answers, there is a limit before you start getting disheartened and feel like it isn't even worth it.

So I haven't had a limit equals one problem in a while, but I have still had eureka moments that I think are worthwhile to me at least. Coming up with an algorithm to find prime numbers for Project Euler just to find out that I have recreated the Sieve of Eratosthenes without knowing about it was interesting and made me go learn about the enhancements people have made to it....

But more on that later.