Thursday, October 13, 2011



Here is a guided tour I created of using JMeter to test a RESTful web service built using Glassfish, Jersey, JTA, JCA, Spring, Hibernate, and MySQL.  The video shows me stepping through all the code involved.

Tuesday, May 31, 2011

Dealing with unexpected complexity

I sometimes use this as an interview question for senior programmers, and the real part of the interview question isn't about the code at all.  It's about how people deal with unexpected complexity.  I start the problem off with this seemingly absurdly simple programming test: Please write code to accept two integers, and return the numbers in an array in sorted order.

Sometimes I see code like this:

int[] SortTwo(int i, int j) {
  int[] result = new int[] {i, j};
  result.sort();
  return result;
}

My comment about this is to ask them to remove the sort() call and code everything themselves, after which I'll get something like this:

int[] SortTwo(int i, int j) {
  if (i < j)
    return new int[] {i, j};

  else
    return new int[] {j, i};
}

And here's where things get interesting.  I say I'm going to change the problem now to SortThree(), and still insist they not use any external function calls.  So I change the signature to look like this: 



int[] SortThree(int i, int j, int k);

and them ask them to write the code to return three numbers sorted in an array.  The interesting thing here is that the code to sort three numbers is "unexpectedly" more complex than the code to sort two numbers.  The real point of this question is to see how a person deals with unexpected complexity.  Here's a solution in Java.



Tuesday, April 26, 2011

Yelp Coding Challenge



I really like this programming challenge from Yelp.  You know that "Search for" box on Yelp?  You do a search and then you get a bunch of review fragments.  The problem asks you to implement production level code to implement the algorithm that extracts the most meaningful fragment from a review (given the search terms) to display in search results - the yellow highlighted bits on the right.

What I love about this problem is that it asks for production level code, and the problem is much deeper than it might appear at first glance.  There are also many different ways to skin this cat and there is no "right answer".

When I implemented this, I had to see how my code compared with the production level code on Yelp, so in the source code (see link below), you'll see some test code that compares the two.  I ended up preferring the results that my code produced in a number of cases.  Here's one example.  What do you think?

Here is the original review in its entirety:
I've only been here once, but that one visit was enough for me to know that the pizza here is awesome. It's as good as it gets. It's just sad that they don't have a joint here in Cupertino, but then again I'd be willing to drive to SF from time to time just to enjoy their pizza. The time I went there, the restaurant was bursting with people. We had to wait for at least half an hour or even more, can't really recall. But let me tell you, it was worth the wait. We had the deep dish pizza, the thin crust pizza, the chicken wings and as we plow through the first round of pizzas, we realize that we want more, so there goes the second round. Another round of the deep dish spinach-feta cheese-mushroom pizza and other yummy stuff, we were good to go. I highly recommend the spinach-cheese-mushroom deep dish pizza.  I would definitely come back and try their other pizzas. Aaaaahhhhh who's down to go grab some little star pizzas with me right now!!! haha four thumbs up (including my two toes hahaha) That's how good this place is! Oh and make sure you go with the right company - that will make the experience a golden one =D
Here is the review fragment that Yelp currently produces:
can't really recall. But let me tell you, it was worth the wait. We had the deep dish pizza, the thin crust pizza, the chicken wings and as we plow through the first round of pizzas, we realize that
Here is the review fragment that my code produces:
We had the deep dish pizza, the thin crust pizza, the chicken wings and as we plow through the first round of pizzas, we realize that we want more, so there goes the second round. I highly recommend the spinach-cheese-mushroom deep dish pizza.
Which review fragment do you like better?

Download a ZIP containing the source code to my solution to this problem.