I often see job posting with a request for "resume, cover letter, and code samples" and this baffles me.

If I am applying for job with little, or no prior knowledge of what types of projects I'm going to be working on, how am I to provide code samples? And even if I have an idea of the type of project, what are they REALLY looking for in my code?

Can you help me out, StackOverflow?

22 accepted

Reading a code sample is like analyzing handwriting, in the sense that it reveals a lot about the way you're likely to do your job:

  • Is it simple, well-organized, and straightforward? This would indicate that you're able to analyze an abstract problem, break it down logically, and solve it in a way others will understand.

  • Does it make proper use of the language? This shows that you understand the tools that are available to you, and you know how to leverage them.

  • Is it commented? At what level? Do you explain your logic and your thought processes so others (and you!) will be able to follow them again?

  • What sort of style do you use? Is the code easy to read? Will it be maintainable?

  • What are the programming interfaces? At the very least, there's an input and an output; perhaps several individual functions as well. Are they designed to be reused? Do they follow best practices of decoupling, cohesion, etc?

  • What is the user interface? Will the user understand what it does? Does it help the user through stumbling blocks? Is it intended by consumption for mortal humans, or only by other programmers in your group?

  • How robust is it? Does it anticipate and handle errors or pathological conditions? Does it reject invalid input? Is there an obvious way to make it crash?

  • Is it complete? Does it address one specific need, or is it generic? Are there obvious deficiencies, or is it ready for prime time?

So a code sample is your opportunity to demonstrate how good you'll be once you get the job. And it's the interviewer's opportunity to understand how much training you'll need, how you'll contribute to the team, and whether you can be trusted with the company jewels.

If you're lucky, as Robert Harvey mentioned, you'll have an opportunity to write some code during the interview. In that case, make the most of your interaction with the interviewer: explain your logic, consider alternative solutions and list the pros and cons of each, ask questions. Add a comment, even though you've just explained it. If you see a very simple improvement that you can make to a line you've already written, explain why it's better and make the change.

As an interviewer, the single most important quality I look for in a candidate is presence: Of course, I need someone who can write Good Code™, but what I want is someone who will interact well with me and my team; someone who can think on their feet; someone who enjoys both teaching and learning every day — in short, someone who gets it.

Good luck in your search!


Code samples shouldn't be required. If they are, that's a -1 for the company, but since no company is perfect, this will not typically be a deciding factor.

All the code I've written is proprietary, and yet I've written good code. Also, most of it has been contributed in part by other people, too, so the "genius" you would read would not only be mine. (Which by the way, you never can tell, when you get code samples from other candidates.) I can't provide samples, and I'm not going to do it: it would be crazy for me to publish company owned code for you to read it. You'll have to trust me.

IF you the company can't understand that some code is not my property, and still require it, then it's an unfortunate situation, because you won't have me as one of the candidates - and I don't know if I'm the best one, but I'm sure I'm a good one.

And no I don't code for a hobby, because 40 hours a week is enough for me.

PS - You can also ask them for clarification if you really want to know what they want. Companies are not all the same.


Code samples.

They are looking for how readable your code is and how well you document. Why hire someone who is going to cost them more in the long run writing spaghetti code? In addition, it shows that you are motivated by coding, and not the salary that comes with it. Intrinsic motivation is a great thing to find.


They're expecting you to have shown enough extra-curricular interest in software development that you've been involved with Open Source projects, or written your own free software.

They want to see the code you've produced for yourself, for fun, to exercise your skills.

Be careful - I do developer recruitment, and I've rejected people because they have published terrible code online.


What I don't get is, if you do give them a code sample, how could they even tell whether it was you who wrote it? How would they know whether you spent stupid amounts of time on it? And how would they know whether it was peer-reviewed and corrected (which I'd guess it should be, if you're submitting it as a portfolio sample)?

It seems to me that they'll be looking in the code sample for the same thing that they'll look for in your resume and cover letter: i.e., they'll be looking for any sufficient excuse to put your application in the 'discard' pile, and skip the time required to interview you. And/or they may be looking for some code which they can discuss with you when they do interview you. They may also be looking for compliance (i.e. for candidates who are willing to jump through hoops).


Some error handling. Comments that explain what's going on without explaining what is obvious from the code. Well named variables + method names that clearly identify what they're purpose is.


They want to know if you can code. A person can have really good credentials and not know how to code. However, I've never been asked for open-source stuff that I've written. That seems like a pretty odd requirement.

If you're not asked for code samples, you should be asked to write code to solve a simple problem while you're at the interview. You would be surprised how many people who claim to be programmers cannot do this.

If a shop is very code-centric (i.e. they want Java, not C#) then I guess code samples might make sense. But what you do on your own time is your own business, and if you've worked for closed-source shops all your life (as I have), you don't have a portfolio of code to show. Generally speaking, I like to make money when I code, and I don't think there's anything wrong with that.

As a hiring manager it's more important to me that a person can code than if he has code already written that he can show.


I think communication is the key. If you are not sure why they require it then it wouldn't hurt to ask. Asking for clarification is part of our job anyway!

If the company doesn't response to your question then either a> they are the wrong company for you anyway. b> you might want to try to approach them from another angle.

Personally, If they want to see any code I would rather do it at the interview.


My former company once hired someone we shouldn't have. We knew that, seeing his code sample. We knew from the code that he would need mentoring -- from his choice of variable names, from the incomplete coverage of edge cases, and from the inadequate error handling. We brought him on as a junior programmer anyway, since we needed people.

We shouldn't have. He consumed more of our time than he contributed in value.

Code samples are nice. Many people don't have a lot of code they can freely show off; as others have said, if it belongs to their (former) employer, they can't share it. But small test cases or puzzles can tell you a lot. I used this XKCD comic a couple of times, both to look at coding style, and to see how people dealt with loosely specified requirements...

I often see job posting with a request for "resume, cover letter, and code samples"...

This job posting is probably written by a clueless HR person ;-)

[The "cover letter" is also a clueless-HR giveaway.]


The only job I ever applied for that wanted a code sample was around 1980. I printed up a PL/I program I was rather proud of. The guy who interviewed me just wanted to see how thick the stack was. He never read a line. Perhaps the moral of the story is to be wary of potential employers seeking code samples?


Proof that you know how to use a printer... unless they are going to grill you on it, I see no point.


It's kind of a ridiculous request, so I'd probably just send along my resume and what not with no code samples. And then, if they asked me where my code samples were, I'd probably withdraw from consideration.