Amazon Black Hat coding question – Tales from the Crypto

Amazon Black Hat coding question

I’m at Black Hat, hanging out at the Amazon booth with my colleagues, and quite amazed at the stir created by the coding question I put up on the board.

Vegas 017

For those of you that haven’t had a chance to see the code, or need more time to figure out what’s wrong, I’m posting the code here. Sadly, no prizes for those of you who aren’t able to come to the booth, and I won’t be accepting posts commenting on the code until after the conference is over.Vegas 015

Consider it a theoretical exercise in code review – how would you handle this Java code arriving in front of you at a code review?

public static boolean isDifferent(
    final MyBean oldBean,
   
final MyBean newBean)
{
      return
        oldBean != newBean &&
       
oldBean != null &&
       
!oldBean.equals(newBean);
}

Post your comments, and after the conference is over, I’ll open them up.

For those of you that think in C++ instead of Java (and there were many at the conference), here’s a version in that language:

public:
    static bool isDifferent(
        const someClass const * oldObject, 
        const someClass const * newObject)
    {
        return
            oldObject != newObject &&
            oldObject != NULL &&
            !oldObject->equals(newObject);
    }

There are no ‘cheat’ issues – code not present in the sample is assumed to be perfect.

8 Responses to Amazon Black Hat coding question

Leave a Reply

Your email address will not be published. Required fields are marked *