News for hackers. Stuff that matters.
Re:How to hire a programmer when you're not a programmer by jswinghammer on Tuesday October 26, 2010 @04:27PM (#1835945)
Or you can just learn a simple programming question or two that you can ask them to write the answer to. Example:

string itoa(int i)

{

//convert integer to its string representation

}

In my experience this will tell you enough about the person's proficiency to make a decision. I've seen so many people fall apart on this question in so many different ways it's not even funny. The ones who get it have all been pretty good hires.

Re:How to hire a programmer when you're not a programmer by rubyrescue on Tuesday October 26, 2010 @05:02PM (#1836084)
I TOTALLY agree and I've never heard anyone say the same thing. My interviews have all been boiled down to:

(a) can they code and TEST int atoi(char *)?

(b) Are they a good cultural fit (ie they like the startup environment)

(c) Then to be sure, I start giving them some real-world challenges we're having with a product and see if they can help.

But (a) eliminates most candidates before I even have to go any further, and if they can do (a) they're generally a good hire. It's kind of bizarre.

Re:How to hire a programmer when you're not a programmer by jswinghammer on Tuesday October 26, 2010 @05:34PM (#1836202)
Atoi is even easier than itoa :)

I hear you. These basic functions make excellent questions.

Re:How to hire a programmer when you're not a programmer by chrisaycock on Tuesday October 26, 2010 @05:36PM (#1836211)
Yeah, I start asking them to code atoi(). That question works miracles.
Re:How to hire a programmer when you're not a programmer by cookiecaper on Tuesday October 26, 2010 @06:59PM (#1836501)
The glibc implementation of atoi basically just offloads to strtol, which just offloads to strtol_l.c, which is pretty complex at first glance.

You're basically testing to see if people know about casts, right? I'm not a big C developer and most of the languages I spend most of my time in have much less onerous typing systems than C, but if you gave me this question I would probably just write something like:

    return (int) char;
perhaps including a loop to read to the end of char*. Would I pass or not? I don't think I'm that bad of a programmer, just don't have a lot of direct experience with C.
Re:How to hire a programmer when you're not a programmer by jswinghammer on Tuesday October 26, 2010 @07:19PM (#1836561)
1) In this scenario you are implementing that mechanism. Casts don't work via magic.

2.) C isn't required. The functions use the C conventions for naming. That's all.

3.) That solution would never work because it would return the ASCII value for the character.

The solution requires that you go through the string multiplying the value you get by the next power of ten and adding it to what you had before. You work from the 1 position back to the front of the string. You also need to ignore non numerical characters.

Re:How to hire a programmer when you're not a programmer by cookiecaper on Wednesday October 27, 2010 @03:28AM (#1837671)
Can I see a functional implementation just for educational purposes here? I don't understand really because I have casted things in C like that before (not in lieu of atoi() with (int) char as shown, but other datatypes) and because in my experience, when I have a read out a string, I have not gotten an ASCII keycode, but the inputted character. Most of my C experience has been on existing open-source projects, so maybe they'd already implemented stuff that glossed over all this.

That said, I don't really understand why this should be a consideration for the programmer at all. C's type system seems to get in the way and slow things down almost as much as it helps (again, limited C experience here) and I don't think that's how these things should work.

Re:How to hire a programmer when you're not a programmer by drtse4 on Wednesday October 27, 2010 @05:49AM (#1837926)
Castings in c doesn't perform type conversion, regarding the implementation just consider that every ascii char has a numerical code (it's int value) and that in the ascii table the numbers are adjacent.
Re:How to hire a programmer when you're not a programmer by spacemanaki on Tuesday October 26, 2010 @08:28PM (#1836751)
>You work from the 1 position back to the front of the string.

You can work from the front of the string to the end and multiply your accumulated result by 10 at each step, can't you?

I might just be misunderstanding your wording, in which case ignore me.

Re:How to hire a programmer when you're not a programmer by jswinghammer on Tuesday October 26, 2010 @09:57PM (#1836933)
I think that might work. My method makes more sense to me but that's because it's just the first thing that came to mind when thinking about the problem.

Your method means you only need to walk the string once which is better. Either way 9/10 interview candidates can't even get that far.

Re:How to hire a programmer when you're not a programmer by BillMartin on Tuesday October 26, 2010 @09:00PM (#1836822)
You're forgetting to -0x20 or -'0'.

I guess this must be soviet russia.

Re:How to hire a programmer when you're not a programmer by rubyrescue on Tuesday October 26, 2010 @10:12PM (#1836971)
as jswinghammer says you have to implement the mechanism that does this. when you do, don't forget negatives, trailing and leading spaces, and non-base-10 numbers (last one is not a requirement).
Re:How to hire a programmer when you're not a programmer by ddlatham on Tuesday October 26, 2010 @04:31PM (#1835968)
How would you judge their answer if you're not a programmer?
Re:How to hire a programmer when you're not a programmer by jswinghammer on Tuesday October 26, 2010 @04:33PM (#1835972)
Learn the answer. It's not very long. You can have some followup questions like "How would you test this?" or "What range of values would this work for?". Most of the time people don't even know what range of values can be stored in a 32 bit integer (or even in the general area). It's pretty easy to learn 3-4 facts to know more than the people you don't want to hire.
Re:How to hire a programmer when you're not a programmer by jpablo on Tuesday October 26, 2010 @04:38PM (#1835992)
Learn the answer.

Then you risk rejecting exceptional candidates who didn't come up with the answer that you learned.

Re:How to hire a programmer when you're not a programmer by aplusbi on Tuesday October 26, 2010 @04:46PM (#1836019)
You could have someone else set up a bunch of unit tests that you can plug the candidates solution into.
Re:How to hire a programmer when you're not a programmer by jswinghammer on Tuesday October 26, 2010 @04:52PM (#1836039)
There are only one or two ways to solve it even remotely efficiently. You can learn both of them.
Re:How to hire a programmer when you're not a programmer by alextgordon on Tuesday October 26, 2010 @07:56PM (#1836668)
Really? There's dozens of permutations for just the function prototype.

    char* itoa(int value, char* str, int base);
    char* itoa(int i, void* (*allocator)(size_t));
    int itoa(unsigned input, char* buffer, size_t buffer_length);
How a non-programmer could recognize the body of the function is beyond me.
Re:How to hire a programmer when you're not a programmer by jswinghammer on Tuesday October 26, 2010 @10:00PM (#1836946)
What's that have to do with anything? In my example the function returns a type of string which doesn't exist in C.

The simplest version of the function is one that takes an integer and returns a string. This isn't a trick question and it's not difficult to answer or judge the answer if you take the time to learn it. Assuming that you're going to be hiring a programmer without one handy to help you then you need to read a few books and learn a few things. It's not that hard if you're sufficiently motivated to learn.

Re:How to hire a programmer when you're not a programmer by alextgordon on Wednesday October 27, 2010 @06:52AM (#1838041)
I was illustrating the point that even the most minor of things can have many completely different looking but acceptable solutions.

There's way way more than "one or two" ways to solve it if a non-programmer is judging. Non-programmers won't have a command of the language necessary to parse uncommon syntax and idioms.

Re:How to hire a programmer when you're not a programmer by jswinghammer on Wednesday October 27, 2010 @08:33AM (#1838253)
If you define the parameters correctly there are really only two ways to solve itoa that I know of. Problems like this always have rules and boundaries.

Besides the people who this question would screen could not tell you what an allocator might even be.

Re:How to hire a programmer when you're not a programmer by EdiX on Tuesday October 26, 2010 @05:40PM (#1836230)
There are only one or two ways if you know what the program is doing, there are many ways to write the one or two solutions in a programming language.
Re:How to hire a programmer when you're not a programmer by jswinghammer on Wednesday October 27, 2010 @09:17AM (#1838428)
I've asked this question 100-150 times now and I think I've seen everything at this point. The working solutions all look the same or pretty darn close.
Re:How to hire a programmer when you're not a programmer by nerfhammer on Tuesday October 26, 2010 @05:57PM (#1836285)
Yea but there may be an unbounded number of approximation methods that aren't the textbook answer but still diagnostic of competence on behalf of the answerer.
Re:How to hire a programmer when you're not a programmer by jswinghammer on Wednesday October 27, 2010 @09:16AM (#1838421)
I want a solution to the problem on the terms I defined or they have to give me a pretty good reason why they can't solve it. I usually give tons of hints and let them ask many questions. This never helps those who can't program.
Re:How to hire a programmer when you're not a programmer by kgo on Tuesday October 26, 2010 @05:04PM (#1836087)
If you, the non-programmer, can learn it, then surely I, the bad programmer, can learn it.
Re:How to hire a programmer when you're not a programmer by jswinghammer on Tuesday October 26, 2010 @05:37PM (#1836217)
You the bad programmer won't. You will get rocked in any such interview because you didn't prepare.
Re:How to hire a programmer when you're not a programmer by btilly on Tuesday October 26, 2010 @05:19PM (#1836137)
Yes, you can.

However there are a thousand equivalent questions that you could be asked. Can you memorize them all? How do you find out what they are?

Re:How to hire a programmer when you're not a programmer by MiguelHudnandez on Tuesday October 26, 2010 @07:54PM (#1836659)
Indeed. At some point, all the preparation and practice is going to turn them into a good programmer!