Ayende @ Rahien

Refunds available at head office

If Program I Can't, Programmer Am I?

Jeff Atwood has posted about the difficulities of some so-called programmers to program. The intersting facts are here. An extremely simple task is given, and quite a bit of people simply can't handle it, or take an undue amount of time to solve it.

A while ago I posted all sort of interesting questions that I would not put in interviews, it was the sort of interview questions from hell. I did a lot of interviews since then, and I have gotten sick of the level of people that I meet.

My current favoriate question is to give them this code:

public class Program
{
   public static void Main(string[] args)
  {
    //print the input string in reverse
  }
}

And ask them to solve it. It has gotten to the point that this is literally the first thing that I would ask a candidate to do. I am not picky, I would accept a solution in any imperative langauge except Ook#. And quite a bit of them simply can't do it. I am usually interviewing people that are supposed to have two years or more of experiance building applications in .Net. And they simply can't do it.

Let me tell you how vicious how I am with this horrible question, I give them a laptop (mine, actually) loaded with Visual Studio + ReSharper, full access to the net (and yes, that include Google), and they still can't do it. In one particular case, I watch the candidate go to google, skip the first result that was titled "Reversing a String in C#" and go directly to a code sample in C(!). He then spent the next five minutes shocking me by trying to get it to compile.

I can think of at least five different ways of doing it, depending on whatever you know that string can be iterated or that it has an indexer. I would expect that even if you didn't know either about string, you would realize that you can use Substring() to do it in a horribly inefficent way.

I can accept people with lack of knowledge, I can accept newbies (no prejustice is good), but I can't accept someone who can't program.

Comments

shawn hinsey
02/28/2007 01:22 AM by
shawn hinsey

That question is kind of confusing. Do you mean to print the contents of the args array in reverse, the contents of an arbitrary index of the args array in reverse, or maybe the contents of every index in the array in reverse?

Luke Breuer
02/28/2007 02:16 AM by
Luke Breuer

@shawn: Confusing questions can be a good thing. Just as you picked up upon the ambiguity, so should an interviewee.

@Ayende: Where do you find these people? I'm not saying that I had a whole lot of faith in the human race already, but this is just disheartening. At least this gives me a competitive edge...

Ayende Rahien
02/28/2007 07:17 AM by
Ayende Rahien

Ah, you already got the first hurdle. I saw some people getting stack on THAT for a while.

The kept trying to reverse the string using the args variable.

I meant reversing the string in args[0].

Ayende Rahien
02/28/2007 07:22 AM by
Ayende Rahien

@Luke,

Where do I find this people?

Trying hiring people that directly from the market, (meaning not through friends and such).

Even when getting screened candidates, I run into those depressingly often.

Alex Henderson
02/28/2007 09:20 AM by
Alex Henderson

Yeah, it's surprising how many coders still go to work to eat their lunch... surely there are other industries to get into (for more money) if your really not passionate about it?!!

string reversed = new string(((args ?? new string[] {""})[0] ?? "").Reverse().ToArray());

Ayende Rahien
02/28/2007 09:24 AM by
Ayende Rahien

Alex, I had to use brace matching to figure it out, but string doesn't have a Reverse() method on it.

Darius Damalakas
02/28/2007 10:19 AM by
Darius Damalakas

Last time i gave a candidate to write a Fibonacci queue.

It took him 15 minutes to write 5 simple statements, all of which where assignment. And then he started me exaplining the algorithm orally, drawing some things on the whiteboards and telling me that we need to use he some simple loop.

After i repeatedly asked him write down the solution, he gave up.

Alex Henderson
02/28/2007 11:08 AM by
Alex Henderson

Sorry, the Reverse comes from System.Query as an Extension Method ;o) (because a string is IEnumerable)

It's a terrible terrible way to do it... I can only imagine the Reverse collects all characters internally as a stack and then feeds them back out again via a yield in reverse order (unless it's optimised for string types) - and then I imagine they probably get collected into yet another list before being converted into an array... lots of needless memory allocation.

Would need to fire up reflector and have a look to be sure of course.

Perhaps once LINQ is in the wild you'll start to have candidates who try it this way because "Reverse" shows up in intelisense for a string.... :P

Ayende Rahien
02/28/2007 12:49 PM by
Ayende Rahien

Cool information, when Linq will be out, it would be the time to the next challenge, capitalize every second character.

Harald
02/28/2007 05:17 PM by
Harald

LOL, that remembers me on an interview I had back then (where I was the Interviewee) where I was asked how to swap the contents of two registers without allocating a third one for buffering. The interviewer mentioned, that it took him quite a while to figure out how to do that and somehow he didn't even expect me to answer.

When I came up with a solution he didn't believe me and tried arguing with me why my proposal won't work. Luckily I got support from a second guy attending the interview, though listening to his arguments a bit longer would definitely have been funny.

Oren Ellenbogen
02/28/2007 06:27 PM by
Oren Ellenbogen

Man, you are killing me :).

If she\he can't reverse a string or capialize every second character, she\he in the wrong business. This is a no-brainer question. We are dealing with much more complicated scenarios on a daily basis so if she\he can not give me an answer within 2 minutes and smile("is this question for real?! he's kidding.. right?) while they are writing it, I don't want her\him on my team.

Ayende Rahien
02/28/2007 06:49 PM by
Ayende Rahien

I wish I were kidding, I have met people that are supposed to be "veteran professionals" that can't do it. You can probably guess that they aren't on my team, nor employed at my company in any development capacity.

Bill Pierce
02/28/2007 07:40 PM by
Bill Pierce

Was curious how M$ would reverse a string in .Net 1.1. This comes out of Microsoft.VisualBasic.Strings.StrReverse:

string reverseThis = "test";

char[] array = reverseThis.ToCharArray();

Array.Reverse(array);

string reversed = new string(array);

Realize the goal is not to find out if the candidate knows how to reverse a string. I can't recall a business requirement in a system I have worked on that said we need to reverse the user's input. I would almost prefer that the candidate DID NOT know how to reverse a string so they can demonstrate their thought process for solving a problem.

Nate
03/02/2007 08:37 PM by
Nate

You people are foolish if you think that such questions help you find skilled programmers or good thinkers

Look at some of the code they have written in the past. Discuss concepts. Dumb ass pop quizzes are useless and if the person is nervous, then you have lost a potentially valuable asset.

Ayende Rahien
03/02/2007 08:57 PM by
Ayende Rahien

@Nate,

No, these type of questions won't find good programmers.

They would find the really bad ones, and that is there purposes, to screen the ones that aren't really programmers from those that can make one end of the compiler from the other.

Frankly, I would have much harder time explaining abstract concepts than writing a bit of code to do such a simple task.

hmm
03/03/2007 09:41 AM by
hmm

Could I use Rebol language?:

reversed-string: head reverse string-to-reverse

or if I don't want to modify original:

reversed-string: head reverse copy string-to-reverse

Robert
03/09/2007 05:32 PM by
Robert

Are you sure you are not interviewing Geography students by mistake?

It amuses me how some people get really touchy about asking programmers to program in an interview. Like you say the objective of the test is to pick out the bad ones, not the good. Anyone can lie on a CV.

Ayende Rahien
03/09/2007 05:36 PM by
Ayende Rahien

If only...

I would have more success with them, at least they would know a mountain from a chair

Comments have been closed on this topic.