views:

1571

answers:

21

We're looking for someone to help us enhance & maintain our high-quality, php-based prototype of a transactional web app. Ideally, who can communicate well, and do both front- and back-end web development (as well as smart/gets things done, etc.). Among other more general things, I've been using this question:

Given this:
    $foo = array(1, 3, 7);
write a function (on this whiteboard) to sum the values of the array.

It seems trivially easy to me, but has caused a couple of deer-in-the-headlights situations, which always makes me feel like a villain.

I've read a number of posts here and there (including both Joel's and Jeff's) saying that how candidates think, design skills, passion, etc. are more important than any specific technical skill, and I agree with that. Also, I can see that programming at a whiteboard is a little unrealistic. OTOH, this seems so basic to me that I'm inclined to see it as a fine first-pass filter between front-end devs (who know their way around html, css, and how to copy-and-paste a js function or two), and people who can really code. Thoughts?

A touch more info: I'm open to all sorts of answers: array_sum, a for loop, a foreach loop. Heck, if they want to write an ArraySum class, that would be overkill, but just fine. Using javascript, or another language would be fine, if they're more comfortable with that. Even attempts with minor errors would be ok, but I've had a couple of complete freezes, so I just wanted to sanity check myself.

+1  A: 

Actually, this questions seems kind of... easy.

I suppose writing it on a whiteboard makes it more difficult, though.

R. Bemrose
+12  A: 

No, it isn't too hard. If someone doesn't understand the concept of a loop or how to iterate through an array, they're not qualified as programmers. I'd also want them to know that there's a built-in function for that (array_sum()), or at least where to look for it.

You might want to take a look at The Five Essential Phone-Screening Questions, although you'll probably have to rework them a bit to suit your needs.

Emil H
As someone who works in as many different languages as there are days of the week, I wouldn't count against anyone that doesnt know or remember off-hand the existance of array_sum -- especially given how many narrowly purposed and obscure built-ins there are in PHP. That said, *anyone's* first instinct for a question like that given should be a loop.
EvanK
Yes, that's a valid point. I would want them to know where in the manual to find it, though. Duplicate functions all over the code base is among the worst things I know of. :)
Emil H
My first thought was that there might be a function built in for this, and 9 times out of 10 there is, so I'd expect a candidate to at least look first before providing some sort of iteration (if array_sum didn't exist) common of other languages.
Ross
I think it would be reasonable to expect a pseudocode solution on the whiteboard, and a statement along the lines of "there's probably a 'sum' function in PHP that does this for you, but I'd have to ask Google for the syntax."
Adam Jaskiewicz
+2  A: 

It's not too hard. If they cannot answer that question, they obviously cannot code their way out of a wet paper bag. I would definitely not hire such a person for any kind of development work.

Question is, how could you improve your recruiting process to avoid interviewing these candidates in the first place? Sounds to me like you're not screening your applicants enough before inviting them in for a chat.

Ville Laurikari
+1  A: 

(I think the array_sum($array) method, as part of PHP, will do the job.)

The question really is trivial. Although there is enough space for error in a stressful situation but summing up an array should be easy enough for anyone with basic programming skills in any language.

It would take a dunce to muck up an interview with a question like this. The question is not too hard, it's actually very lenient.

Peter Perháč
I just assumed "without using array_sum" was implied.
R. Bemrose
How about without array_map? foreach? reset-each-next? reset-current-next? while array_shift? There are many ways to do this in PHP.
jmucchiello
+2  A: 

If your applicant can't write a simple for loop and some addition on a whiteboard, you absolutely don't want them touching your code. Even as a front-end developer, they'll be using for loops all the time to output lists, table rows, image galleries and the like.

seanmonstar
+6  A: 

My own view is that there is a limit to the kind of toy questions you could ask for programming on a whiteboard. At best, these are simply toys that are often circulated on online forums and your candidates will memorize.

Most PHP developers created visible websites - you could see their work.

To me, a much better question would be to give him a complicated piece of your own production code and have him explain what it does or how it can be improved, etc. Most of the time will be spent doing maintenance anyway, better get an idea on his code reading skill, not just code writing.

Uri
One problem with giving production code at an interview is that the candidate is probably not familiar with the domain problem, or the conventions and terminology of your application. Still I agree that code reading and understanding skills are of utmost importance.
javashlook
I actually had a recent interview where I got a piece of production code and was asked to figure out what was going on and what they were trying to do. It was very interesting. The rationale was that if I was to start tomorrow, they want to make sure I can dive in.
Uri
+3  A: 

This is the type of basic thing you ask on the phone before bothering to bring a candidate in house.

There are a couple of standard things I ask every programmer about: Do a select on two tables to give a sum of a column in the second table, delete records from one table based on values in a second, difference between an object and a string as a method parameter, and a couple of html/css related questions.

Within 5 questions I can weed out 90% of the candidates before I even see them. The rest of it is going to boil down ideology.

Chris Lively
Unfortunately, I don't really have the opportunity to do pre-screening....
sprugman
+1  A: 

This question should be easy for people that have programming experience, but I'm guessing you may be getting a lot of designers that picked up PHP by copying/pasting code snippets in place.

Maybe you need to update your job listings to make them more programming centric and avoid web design terms.

Chris Bartow
A: 

It depends on what you're trying to ask. Are you screening their ability to recall syntax? Or are you looking for best-practice methods in dealing with array functions? If it's the first case, your question is fine.

On the other hand, if you're trying to see how well a person actually understands code, and knows implications based on how something is structured, the question is good, but instead of requiring them to write a line by line function, invite a discussion on how they would do it, and what would be some considerations with their answer. Why not do it via method B?

IME, asking for rote memory responses (syntax recall, port numbers, etc etc) tells you some aspects of an individuals ability, and sometimes need to be asked. But more important is digging into their problem solving abilities.

patjbs
A: 

I don't see why anyone would have any problems with that. (Assuming that they are developers) And yes, programming at the whiteboard is unrealistic but that is a trivial question which any developer should be able to solve.

schmrz
+40  A: 

I would consider that much too easy of a question, personally. If someone asked me that question in an interview I'd probably be busy trying to figure out what the "trick" was, because it's so simple.

I think it's fine for weeding out the absolute worst programmers, but make sure that you don't have one particular "right" answer in mind and refuse to accept anything else. For example, don't only accept "use the array_sum() function" as the correct answer, where it's really just a test to see if they know the function exists.

I mention this because my fiancee once had a programming interview where she was asked how she would reverse a string. She gave several different algorithms that would accomplish it, with the interviewer telling her that she was wrong after each one. She finally gave up, and he (disapprovingly) told her that she should have just used the String.Reverse() function.

Don't do that. Please.

Chad Birch
+1. Best answer so far. :)
Emil H
+1 for your fiancee if she managed to not choke the interviewer.
lush
there was never a question in my mind of only accepting the "array_sum" method, though that's one of the things I like about this question: if someone knows php pretty well, they'll know that function, but if not, there are still lots of standard ways of doing it. The "trick question" aspect is definitely there, but I'm pretty sure that's not the problem I'm running into.
sprugman
and after all the question was if it is "too hard for a *php dev.* job"? I'm quite positive you don't want someone who is unable to come up with *some* solution in php.
VolkerK
My answer would be to have a look in the PHP manual first to see if such function already exists. Otherwise a for/foreach loop.
DisgruntledGoat
+4  A: 

no, it isn't too hard, but it may cause people to panic if they do not exactly remember the syntax (though if you specifically ask for a php dev, then they should at least remember some syntax). Ask for pseudocode instead, if they still cannot do the question then there is a problem :)

yx
+2  A: 

This question may be better improved by providing the documentation for the array() function, because if they don't know what it is, they could very easily look it up themselves in a job.

samoz
array() is incredibly basic syntax for php.
sprugman
+1  A: 

No, it's not hard. What you've discovered is that there are a lot of "programmers" out there who can't program - they can memorize, they can copy and paste, but they don't actually understand what they are creating (in most cases they seem totally unaware of their lack of understanding).

This lack of understanding becomes painfully obvious when they are asked to write something simple from scratch - writing just the glue code, without all the complex stuff that they'd normally just grab as code snippets and then shift around until the compiler stops complaining.

In general you want to avoid these people like the plague, as they will consistently produce buggy code and will not understand why you or your customers think it doesn't work.

Jeff wrote about this a few years ago: Why Can't Programmers.. Program?

David
+2  A: 

If you can't write code to sum an array (in whatever language you prefer) I don't know what you can write. What on earth do you think someone could contribute to your project if they can't write code to do that question?

mquander
A: 

I had a deer-in-the-headlights moment wondering what the trick was!

Anyone applying for a programming job will know how to add integers together (one way or another, even if it's in a loop), so I'd skip it and find something more challenging....but not so confusing! :)

Ashley Williams
How is that confusing?
grieve
Just because it's so simple. I'd think a lot of applicants would waste a good amount of time wondering what they're "missing", and if it's really as simple as they think it is...
Ashley Williams
@ashleyw: The question is stated so plainly, that if it were a trick question, I really wouldn't want to work there anyway. In that light I would just answer the question as asked. Part of programming is understanding the problem at hand, and cutting away any unneeded complexity. Unless the question itself looked tricky, there is no reason to add complexity.
grieve
+5  A: 

Short Answer: No

Edit: Just to clarify I don't think this is a hard question at all. Regardless of the language. As others have posted, even if they can't get the syntax correct, the should at least be able to write it out in a reasonable pseudocode.

Long Answer: I often ask interview questions I expect the candidate to miss. One could classify them as too (hard|vague|open-ended), but I am not really looking for an answer. I am looking to see the following:

  • Do they try to answer the question? Some people just give up immediately
  • How do they approach the problem? Even if they go down the wrong path are they generally making good assumptions and asking good questions?
  • How well do they maintain composure under stress? The question is designed to be hard, and therefore will be stressful. Do they panic, remain calm, withdraw, talk it out, etc...?
  • Are they able to find the solution if I give them hints and pointers? Or how well do they listen, and do they assimilate new information quickly?

Occasionally I am surprised with a candidate who is whip-smart, and just codes up a quick and elegant solution. Those are definite keepers. But I also find good candidates by people who miss the final solution, but are clearly thoughtful, logical, and given enough time would eventually solve the problem.

grieve
+1  A: 

To be honest, I would like to think that if a person applies to a programming position, he or she will probably have the relevant skills on their resumes. Why not ask simple problem solving questions instead if the position doesn't require some sort special skills in the language in question? I was once asked how many pizza stores there are in my country. They were interested in checking how I approached the problem and weren't really interested in how awesome I might be in the relevant programming language. I think that was a good way to go about it. Am I awfully wrong in thinking that?

Edit: Or is it very common that people fake their resumes?

daft
Unfortunately many people do not have the skills they claim to have on their resumes.
HLGEM
A: 
vartec
+6  A: 

in my opinion, the question is perfectly valid, and tells a bit (not a lot, but an important bit) about the candidate, depending on how much time you invest in it. just tell her that it's not a trick question beforehand, that it's really, really as simple as it appears, so she doesn't spend to much time thinking about the pitfalls and to minimize the deer-situation. throw in you do that just as a measure to filter out the people who apply for a programming without actually knowing anything about it but hoping they get hired anyway by pure luck (if they know how to code but are just nervous, that should take a bit of pressure away). let them code, but don't focus if there is a $ missing or if the <?php tags are present or not.

if she provides array_sum or sum_array as an answer almost doesn't matter, especially if the language in question is php (but if two candidates are equal otherwise ... i can't even remember the last time i had to use this function). and the use of an auto-completion and syntax-coloring (with predefined keywords) IDE vs. a dumb text editor matters a lot in this hindsight. in this case ask for an alternate, handcrafted solution.

if i was in the position of asking that question i wouldn't ask for the right solution, i'd ask for ways that come to her mind how this problem could be solved, what pitfalls could arise in special cases. try to find out what she knows about programming, not what she knows about php. try to find out about intelligence, problem solving and creativity. altought experience matters a lot even when it comes to bang out code fast, it's not a constant.

the solutions i'd provide, the pros/cons and what it tells about me ...

  • built-in array_sum (very fast and definitley not buggy, but inflexible): i have a bit of experience with traditional php projects

  • for/loop constructs (good enough, reinventing the wheel. but can be used if there are different objects than numbers. pros: everybody will understand it): i can solve simple problems if there are no predefined copy&pasteable solutions

  • array_reduce (with an offering to implementat array_reduce, if the interviewer wants to see it): unusual for a php programmer, so it seems i have knowledge and experience outside of the php sandbox

  • an ArraySum-Object (with an ArraySum::add($value) method that keeps all values stored but caches the sum): i'm used to at least some of the oop-principles

  • function () { return 11; } (with the disclaimer that this is a joke solution, but valid): i have (albeit crude) programmer-specific humour - a sign i'm personally interested in programming outside of work ... some interviewers who are programmers (but not hackers) might interpret this as a willingness to use dirty hacks as placeholders (aehm) if time constraints are too tight

  • a recursive solution would be nice. i can probably solve a bit more complex, algorithily problems too and most likley know my way around simple trees and data structures

  • recursive divide and conquer: bonus! i know even more about algorithms.

try to get as much as possible out of this question (if time permits). in the end you'll know a little bit about programming capability and a lot about experience (altought not necessarily PHP specific).

i'd choose this question over letting the candidate write out quicksort - a very specific question about knowledge almost never needed in the web dev world - any time.

disclaimer

the question is useless when ...

  • the interviewer is not a programmer. forget it if a hr-guy is doing it
  • there's a very tight time constraint when interviewing. then the result is almost random anyway.

additionally, who are you looking for? if you need a cheap grunt coder, even a simple question like this should work. if you need quality and experience, don't waste too much time on it (but do it anyway).

Schnalle
It's meant to be a quick first-pass question to separate the people who can program from those who are really front end devs who have played around with customizing joomla or drupal a bit.
sprugman
+1 for `function(){return 11;}`
thephpdeveloper
+1  A: 

My favorite would be:

while ($foo && $sum += array_shift($foo)) continue;
Heh, the forc.. perl is strong in this one :P (ok I DO know it is not perl, but php, but it is still very perlious)
shylent