// Internet Duct Tape

Writing code in interviews – The Guerrilla Guide to Interviewing – Joel on Software

Posted in Hiring, Job Interviews and Resume Resources, Links, Technology by engtech on April 24, 2006

Some signs of a good programmer: good programmers have a habit of writing their { and then skipping down to the bottom of the page and writing their }s right away, then filling in the blank later. They also tend to have some kind of a variable naming convention, primitive though it may be… Good programmers tend to use really short variable names for loop indices. If they name their loop index CurrentPagePositionLoopCounter it is sure sign that they have not written a lot of code in their life. Occasionally, you will see a C programmer write something like if (0==strlen(x)), putting the constant on the left hand side of the == . This is a really good sign. It means that they were stung once too many times by confusing = and == and have forced themselves to learn a new habit to avoid that trap.

>> The Guerrilla Guide to Interviewing – Joel on Software

>> The Guerrilla Guide to Interviewing 3.0

4 Responses

Subscribe to comments with RSS.

  1. engtech said, on April 25, 2006 at 5:16 pm

    And yes, the next day after I posted this article I get an interview with the “reverse a string in place” question. And try to do it with pointer arithmetic. And completely screw it up because I didn’t brush up on my pointer arithmetic.

    or programming questions, I ask candidates to write a small function in C. Here are some typical problems I would ask:

    1. Reverse a string in place
    2. Reverse a linked list
    3. Count all the bits that are on in a byte
    4. Binary search
    5. Find the longest run in a string
    6. atoi
    7. itoa (great, because they have to use a stack or strrev)

    You don’t want to give them any problems that take more than about 5 lines of code; you won’t have time for that.

    Let’s look at a couple of these in detail. #1: reverse a string in place. Every candidate I’ve ever interviewed in my life has done this wrong the first time. Without exception, they try to allocate another buffer and reverse the string into that buffer. The trouble is, who allocates the buffer? Who frees the buffer? In giving this question to dozens of candidates I found out an interesting fact. Most people who think that they know C really do not understand memory or pointers. They just don’t get it. It’s amazing that these people are working as programmers, but they are. With this question, here are some ways to judge the candidate:

    * Is their function fast? Look at how many times they call strlen. I’ve seen O(n^2) algorithms for strrev when it should be O(n), because they are calling strlen again and again in a loop.
    * Do they use pointer arithmetic? This is a good sign. Many “C programmers” just don’t know how to make pointer arithmetic work. Now, ordinarily, I wouldn’t reject a candidate just because he lacked a particular skill. However, I’ve discovered that understanding pointers in C is not a skill, it’s an aptitude. In Freshman year CompSci, there are always about 200 kids at the beginning of the semester, all of whom wrote complex adventure games in BASIC for their Atari 800s when they were 4 years old. They are having a good ol’; time learning Pascal in college, until one day their professor introduces pointers, and suddenly, they don’t get it. They just don’t understand anything any more. 90% of the class goes off and becomes PoliSci majors, then they tell their friends that there weren’t enough good looking members of the appropriate sex in their CompSci classes, that’s why they switched. For some reason most people seem to be born without the part of the brain that understands pointers. This is an aptitude thing, not a skill thing – it requires a complex form of doubly-indirected thinking that some people just can’t do.

  2. engtech said, on April 25, 2006 at 5:26 pm

    The correct solution.

    char *str_rev(char *p_str)
    char tmp, *front = p_str, *back = p_str;

    assert(p_str != NULL);

    while (*back) {

    while (back > front) {
    tmp = *back;
    *back = *front;
    *front = tmp;
    return p_str;

  3. […] Joel has another great post on phone interviews. He focuses on asking questions on programming skills and office politics, with an emphasis on putting forth incorrect assertions and seeing if the interviewee pipes up. “Smart programmers have a certain affinity for the truth, and they’ll call you on it.” He also gives a list of good interview questions like how to design a program for playing Monopoly. This isn’t his first time talking about interviewing, he also gave some good tips in his Guerrilla Guide to Interviewing. It happens all the time: we get a resume that everyone thinks is really exciting. Terrific grades. All kinds of powerful-sounding jobs. Lots of experience. Speaks seventeen languages. And saved over 10,000 kittens! […]

  4. jack said, on January 09, 2007 at 1:57 am

    Nice site actually. Gone to my favourites. Thanks for creation.

Comments are closed.

%d bloggers like this: