- It is difficult to have a candidate write a substantial amount of code during an interview.
- A code sample should be shown to the interviewee and they should be asked to circle the problems and give solutions.
- The code sample should be between 30-50 lines of code and have various problems with it.
- The problems should be at different skill levels to decipher.
- Depending on the level of issues found, an assumption about the interviewee's code quality can be made.
Unless you have very long interviews, it is very difficult to have a candidate write a substantial amount of code. Â I think an interview can reliably deal with this by showing the interviewee a code sample and asking them about it.
This code sample can not be a simple HelloWorld program. Â It needs to compile correctly and have runtime, various style problems, and good coding practices problems. Â These problems need to be at different skills levels to decipher. This code sample would be printed out and given to the interviewee. Â Ask them to circle the problems and give them 5-10 minutes. Â The interviewer would look at the various items that are circled. Â The interviewer would ask why the interviewee circled a particular item and then ask how the interviewee would fix it. Take the following code for example:
public class CodeTest { public String getString() { String theimportantstring = null; if (theimportantstring.isEmpty()) { theimportantstring = "something very important "; theimportantstring.toUpperCase(); theimportantstring.trim(); return theimportantstring; } else { theimportantstring = "something slightly different but very important "; theimportantstring.toUpperCase(); theimportantstring.trim(); return theimportantstring; } } }
This gives a very brief example.  I think the code sample should be between 30-50 lines of code, but it gives the general idea.  This code compiles but have various problems with it.  First, it will give a NullPointerException when run.  This is a straightforward issue in the code.  There are other more subtle problems.  There are no comments.  The variables name switch from CamelCase to all lowercase.  There is copying and pasting in the method. Depending on the level of issues found a general assumption about an interviewee’s code quality can be ascertained.  The amount of time spent is not significant and the interviewer can get an idea of the interviewee’s programming knowledge by how they would fix the issue.