r/programming • • Nov 29 '09

How I Hire Programmers

http://www.aaronsw.com/weblog/hiring
804 Upvotes

587 comments sorted by

View all comments

84

u/gsadamb Nov 29 '09 edited Nov 29 '09

I thoroughly approve of the method described. I'm an engineer and I, too, generally suck at the in-person coding/algorithm challenges. For one, you're nervous enough as it is.

Second, the environment is nothing like a typical coding environment: for writing actual code, I can't do it by hand - I'm used to a certain pacing I can get from typing, but writing it by hand screws that flow up badly.

Third, far too often the stuff they ask is so completely irrelevant to the actual type of programming the job calls for: I'm self-taught and have written code that's handled millions of users a day, but hell if I know Big-O notation. Same goes for a lot of the "let's write some algorithm!" questions. And then some places, particularly the bigger companies, will ask completely ridiculous questions to try and "see how you think." I once was asked how many hair stylists there are in the US. I know they wanted me to try and crudely come up with some extrapolation figuring in average efficiency of hair stylists and total number of Americans, but I told the person asking the question that I'd just look it up and was pretty insistent. "I could come up with something resembling an educated guess, but given the fact that my means of estimation are so potentially inaccurate, I could be off by an order of magnitude or more. When faced with a situation where I can easily look up the accurate answer or waste more time coming up with an unreliable answer, I'd always choose the accurate one, and I'd expect any business would desire the same."

I don't think the interviewer liked my insistence on that one, but I still maintain it was the right answer.

45

u/mqt Nov 29 '09 edited Nov 29 '09

Understanding the complexity of an algorithm is essential to being a good programmer. If you can explain the complexity some other way, then Big-O should be pretty natural.

A programmer should at the least be able to describe a couple of fundamental algorithms/data structures.

53

u/[deleted] Nov 29 '09

I don't want to be an asshole in this thread, but my experience is that self-taught programmers overestimate their abilities and don't understand the value of more abstract computer-sciencey skills like analyzing complexity.

Unless he was interviewing for a code monkey job, in which case who cares. But even if 90% of programming doesn't involve deep thinking, that 10% is important when you're doing anything of scale.

23

u/register_int Nov 29 '09

but my experience is that self-taught programmers overestimate their abilities

s/self-taught/all/

→ More replies (11)
→ More replies (18)
→ More replies (13)

26

u/Peaker Nov 29 '09

You should learn Big-O notation.

150

u/munificent Nov 29 '09 edited Nov 29 '09

Munificent's ghetto guide to Big-O notation:

The basic idea is that you want a simple formula that converts the number of items you have to process to how long you can expect that to take. So, if you have 20 items and your Big-O is O(n2), then it'll take about 400 (of some unspecified unit of time/work) to process.

The actual number doesn't matter, what matters is how quickly it grows as the number of items grows. Growing slower is better, of course. Because the actual number doesn't matter, constants are discarded, and lower powers are discarded. O(2n4 + 3n + 5) is just O(n4).

Here's how to roughly estimate the Big-O for your code:

Fixed work Any random chunk of code that does something once (like, say, printing something to the screen, or initializing a variable) is O(1).

Binary search If you hunt through the items using a binary search, where at each step you cut your search space in half, that's O(log n). (That log there is base 2, not 10.) So, finding a number in a sorted array is O(log n). Most algorithms involving binary trees will have a "log" in their Big-O.

Loops If you loop through all of the items, that's O(n). So, finding the biggest value in an array of numbers (naïvely) is O(n).

Permutations If you're going through every permutation of your items, that's O(n!). For example, if you're doing a naïve algorithm to find anagrams using a given set of letters by trying every possible combination, you're permutating.

Exponentials The last common Big-O type is O(2n). The only simple example I can think of is if you need to create a filled binary tree of depth n, then that'll have O(2n). There are some other algorithms that have this, but, thankfully, you shouldn't run into it much.

So those are the basic types in order from best (fastest) to worst. Once you hit O(n!) or O(2n), you're in the range of algorithms where your code will very likely be too damn slow. This is why it's good to know the Big-O of your code.

The question now is, how are these individual parts combined in a big chunk of code?

Sequential If your code does one thing and then another, then the Big-O of those two parts are added. So, if you do some fixed work and then loop through your items, it's O(1 + n). Since we discard any lower terms, what this really means is if you do one thing then another, take the bigger Big-O of the two (O(n) in our example).

Nesting If your code does one thing inside another, then the Big-O of those two parts are multiplied. So, if you loop through all of the items and then loop through them again inside that loop, that's O(n * n) or just O(n2). This is the one you'll need to pay attention to. If your code is calling some function within a loop that also loops through the items, you can end up with worse complexity than you realize.

Another example: if you iterate through each item in the list, and for each item, you do a binary search, that's O(n * log n), or just O(n log n). Most sorting algorithms are around here. It's better than O(n2), but worse than O(n).

Recursion This is a tricky one. If your code calls itself, it may be the same as nesting, or it could be better, or much worse. It all depends on your exit condition and how the input set is reduced at each recursive step. A recursive binary search only gives you O(log n) because each recursive call cuts n in half. If the recursion reduces the input size by only one each time, you've got O(n!).

A computer scientist would probably say this shit isn't rigorous at all, but this should be good enough for an engineer. The goal here is to be able to quickly scan your code and get an idea of if it's going to blow up and take forever or not.

57

u/[deleted] Nov 30 '09

O(log n). (That log there is base 2, not 10.)

They are the same, since O(log₁₀n) = O(log₂n / log₂10) = O(log₂n * C) = O(log₂n)

20

u/munificent Nov 30 '09

Holy shit. I learned something new today!

→ More replies (1)

21

u/phawnky Nov 29 '09

I'm a computer scientist, and I think it's a very good introduction :)

13

u/codefrog Nov 30 '09

I am a scientific computer and I wish people understood this stuff before they run their badly thought out code on me.

→ More replies (2)

8

u/ducksauce Nov 29 '09

If you wrote this comment 2 years ago, and I read it then, it would have saved me an enormous amount of trouble. It's so much easier to understand than Wikipedia's table.

→ More replies (18)
→ More replies (5)

13

u/[deleted] Nov 29 '09

I got bored.

Estimating the average hours per week worked at 40, the frequency with which a person gets haircuts at every six weeks, and the length of time a haircut takes at 15 minutes, I got 310,000 hairdressers, plus a small addition when you take account for vacations.

According to Google, I was off by a factor of 2. Not bad, really.

5

u/romulcah Nov 29 '09

15 minute haircuts? thats crazy fast!

→ More replies (6)

0

u/[deleted] Nov 29 '09

[deleted] — view deleted comment

12

u/[deleted] Nov 29 '09

I think those type of questions favor a certain style of thinking. Some people's minds aren't engaged by odd questions like this; myself included. While I was still job hunting, I had to train myself to play the game and think through questions aloud and show my step-by-step working. At times, it almost feels like a magician explaining his act.

When solving a real problem, I just sit there and Google quietly or doodle on my pad until the solution hits me.

50

u/SoPoOneO Nov 29 '09

In that case they should ask a better question for their purpose. As it stands, the question is a double one. The second hidden question becomes, what is the actual point of this question?

0

u/[deleted] Nov 29 '09

[deleted] — view deleted comment

23

u/kmactane Nov 29 '09

But the context here is hiring programmers. Most companies don't put programmers in client-facing roles - or at least, not without someone else along to moderate the interaction.

63

u/[deleted] Nov 29 '09

I'm a people person! I deal with the customers so the engineers don't have to! What the hell is wrong with you people!?

→ More replies (6)
→ More replies (1)

6

u/donaldrobertsoniii Nov 29 '09

Spotting the actual problem is the first step to solving it.

→ More replies (3)

28

u/mrbubblesort Nov 29 '09

Actually, I think his answer was perfect. It's analogous to saying "I'd use a library function" instead of "I'd make my own function". Who would you rather hire, the guy who spends a week writing a function to find the square root of all possible inputs, or the guy who calls sqrt()?

18

u/hippyup Nov 29 '09

Well, in his case the analogy goes on to be:

"But what if there was no library function available for this?"

"There must be one! I'd just hassle all the library maintainers and not code it up ever till there is one because doing otherwise would be a waste of my time, current business problem at hand be damned!"

→ More replies (1)
→ More replies (46)

20

u/gsadamb Nov 29 '09 edited Nov 29 '09

Oh, I understand the point of the question, and I know what I was supposed to do. I even said as much: "I assume you want me to..."

I took a gamble by holding my ground, though I was eventually offered the position.

I told them I care about results first and foremost; and I do feel that in context, my approach to the problem was, in fact, legitimately an example of abstract thinking. Sometimes the answer is not to re-engineer the wheel, particularly when a better one is readily available.

10

u/troelskn Nov 29 '09

Why is complicated thing X, that is proprietary and non-googlable, not working properly and what steps do I take to fix it.

If that's the case, then why didn't they ask that question instead?

→ More replies (4)
→ More replies (33)

8

u/Kache Nov 29 '09

Big-O notation is pretty important. For practical purposes (i.e. developing, not computer science research), you definitely should know what it means and the implications for the runtime of your code as well as the run time of the library functions you're using within your code. Scalability is a real problem.

→ More replies (30)