You Are Not a Compiler!

DZone 's Guide to

You Are Not a Compiler!

Enjoy tossing out code puzzles at conferences? What about during recruitment? Here's what's wrong with them and how you can do better.

· Java Zone ·
Free Resource

At conferences, it’s common to get gifts at booths. In general, you need to pass some sort of challenge.

An Innocent Puzzle

Some of those challenges involve answering a code puzzle, like the following

What would be the output of running the following snippet:

public class Sum {

    public static void main(String[] args) {
        System.out.println(0123 + 3210);

  1. 3293
  2. 3333
  3. The code doesn’t compile
  4. The code throws an IllegalArgumentException
  5. None of the above

My usual reaction is either to leave the booth immediately or, if I’ve got some time, to write the code down on my laptop to get the result (or search on Google). You could say I’m lazy, but I prefer to think I’m an expert at optimizing how I spend my time.

Simple But Useless

There is a single advantage to this approach: anybody can grade the answers — if the correct results are provided. And that’s all.

Otherwise, this kind of puzzle brings absolutely nothing to the table. This wouldn’t be an issue if it stayed on conference booths or as a "fun" game during breakouts. Unfortunately, the stuff has become pretty ubiquitous to filter out candidates during recruiting or to deliver certifications.

In both cases, skills need to be assessed, and the easy solution is through a multiple-choice question test. Of course, if one has no access to an IDE or Google, then it becomes a real challenge. But in the case of the above sample, what’s being checked? The knowledge of a very specific corner-case. I would disallow this specific usage on my projects anyway for this exact same reason: It’s a corner-case! And I want my code to be as free of corner cases as possible,

Another Sample

This is also another kind of puzzle you can stumble upon:

In the class javax.servlet.http.HttpServlet, what’s the correct signature of the service() method?:

  1. public void service(ServletRequest, ServletResponse)
  2. public void service(HttpServletRequest, HttpServletResponse)
  3. public int service(ServletRequest, ServletResponse)
  4. public int service(HttpServletRequest, HttpServletResponse)
  5. protected void service(ServletRequest, ServletResponse)
  6. protected void service(HttpServletRequest, HttpServletResponse)
  7. protected int service(ServletRequest, ServletResponse)
  8. protected int service(HttpServletRequest, HttpServletResponse)

This kind of question asserts nothing but the capacity to remember something that is given by the most basic of IDEs or the Javadoc.

Note: In fact, the complete title of this post should have been "You’re not a compiler, nor a runtime, nor the documentation".

The Core Issue

There is no single proof of correlation between correctly answering any of the above questions and real-world proficiency of applying the skills they are meant to assess. Is there an alternative? Yes. Don’t simply check shallow knowledge, check what you want to assert, under the same conditions, including IDEs, documentation, Google, etc.

  • Do you want to check if candidates are able to read code? Make them read your own code — or similar code if your code is secret.
  • Do you want to check if candidates are able to write code? Make them write code, e.g. fix an existing or already-fixed bug.

The same can be done in the context of certifications.

Of course, the downside is that it takes time. Time to prepare the material. Time to analyze what the candidate produced. Time to debrief the candidate.

Is this feasible? Unfortunately for those who would cast that aside as a utopia, it already exists. The best example is the Java EE Enterprise Architect. Though the first step is a multiple-choice test, other steps include a project-like assignment and an associated essay.

Another example is much more personal. I’m working as a part-time public lecturer in higher education organizations. In some courses, I evaluate students by giving them an assignment: Develop a very small application. The assignment takes the form of specifications, as a business analyst would.


For the sake of our industry, let’s stop pretending puzzles are worth anything beyond having some fun with colleagues. You should be more concerned about the consequences of a bad hire than the about the time spent on assessing the skills of a potential hire. There are alternatives, use them. Or face the consequences.

career advice ,code challenge ,java ,recruitment

Published at DZone with permission of Nicolas Frankel . See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}