35

I have gotten requests to submit code samples (from past work completed) but I have never really understood what precisely these employees are looking for.

Do they care how complex they think the past work done is? Or are they looking to see how much you commented your code? Or are these interviewers looking for code that works?

What do you suggest one do when asked for code samples?

0

8 Answers 8

32

When I ask for code-samples, what I'm looking for is something to discuss in a technical interview. Something along the lines of "Why did you choose [not] to do this?"

A lot of this is about gauging your reaction. Will you get defensive / aggressive? Do you know why you did something? Did you know the alternatives? Do you think that people who would have made a different decision are idiots? Can you hold your own in a disagreement, or do you cave because I'm in a position of authority?

Sadly, the alternative to code samples is asking you to write some code for me in an interview situation, which I consider too short a time and too high-pressure for me to actually learn anything.

All that said, if you don't have any code samples that you can provide, I will give you an arbitrary problem to solve in your own time. Beware any company that doesn't give you that option. They're generally the ones who believe you should spend your entire life coding, preferably for them.

6
  • +1 This is a good answer to the question, as it clearly states one of the most important reasons that employers (I do this, too) ask for code samples: to see how you react when you and your code is interrogated.
    – jcmeloni
    Commented May 15, 2012 at 12:14
  • I don't get what you're saying, last paragraph. Why does not being given the option to solve an arbitrary problem something to beware of? What is the connection between not being given an arbitrary problem option, and employer having a kind of "overly high expectations" attitude towards employees?
    – bobobobo
    Commented Nov 15, 2013 at 2:24
  • @bobobobo: If a company expects you to have recent code-samples to hand, without recognition that you probably have a contract with your current company that forbids use of their code, I think it's fair to assume that their expectation is that you have no life outside coding.
    – pdr
    Commented Nov 15, 2013 at 9:04
  • 3
    Given what everybody's saying here, my advice would be to solve an http://projecteuler.net/ problem and send it in. I wouldn't bother sending any code you consider special because they don't want special, they want talking points.
    – bobobobo
    Commented Nov 15, 2013 at 21:27
  • @pdar - why do you think that the company which does not give a task to solve, believe that you should spend entire life coding, preferably for them? Commented Aug 2, 2016 at 6:47
24

You should take as much care with the preparation of sample code as you do with your resume. The purpose is to sell your skills to the potential employer.

As an interviewer what I looked for was code that made sense and would work. I looked for code that showed a level of complexity consistent with the job I was hiring for. A code sample for a senior devloper would be expected to be more complex than one from a junior developer. I looked for the abilty to adhere to a consistent style (it didn't have to be the style we preferred, but should be internally consistent). I was looking for evidence of a cowboy coder who didn't care how maintainable the code was (something that would not be a good thing). I wanted the code to be something that shows you can solve the types of problems I have.

But most of all I was looking for the code to be something the person could explain to me. You would be amazed at how many times I have gotten a code sample when that person could not explain what it did or how it did it. And if it was something that you are personally proud of and excited to talk about, that helps too.

Another thing interviewers are looking at when getting code samples is your judgement. Even if you don't have an NDA, we don't want to see code that clearly identifies the company it came from. We want you to tell us that you have specifically modified the code to avoid an NDA and it is not exactly the same as what was actually implemented. Or we want you to tell us it came from a personal project with a link to the the whole project.

We want to see if you gave us code that relates to the job we are hiring for or is at least at the right level of complexity (this is part of the judgement test, have you thought about what kind of code we would want to see). If I'm hiring you to do backend database work, I would expect to see database code. If I'm hiring you to create web sites, I would expect to see some front end code. If I'm hiring to do embedded code in hardware that is the type of code sample I want. If I'm hiring to do games programming, then a game program or at least something showing that you can handle the math involved is what I want to see. I also want to see the solution to an interesting problem.

It's true that most professional code is under an NDA, however it is possible take such code and make it so that the it does something similar to what the orginal code did but is not identifiable to a specific company or process. I believe the proessional who wants a job should have taken the time to create a portfolio of his or her work in such a way as to make it not company-related. The code can be from a personal project or from something that the person rewrote at home to be not under the NDA using concepts similar to things he did at work. Rewriting it in a different language than the one you used at work would be extra impressive. A code sample doesn't have to be a complete application as the interviewer is not going to go through thousands of lines of code. But don't make it so short that it doesn't show your skill level either.

Above all don't make the code sample sloppy or buggy. Handle errors, be consistent in your naming practices, use good design patterns, avoid antipatterns, etc.

1
  • 3
    +1 Good answer, especially to call out "code that showed a level of complexity consistent with the job I was hiring for".
    – jcmeloni
    Commented May 15, 2012 at 13:59
11

To HLGEM's excellent answer I add:

I ask for code samples from junior candidates who don't yet have much of a body of experience to talk about. In addition to the judgement factors mentioned by HLGEM, I look for:

  • an appropriate amount of modularization/encapsulation. This can be over- and under-done; I'm looking for the right balance taking into account future maintenance, extensibility, and the expressibility that might reasonably be needed.

  • sound choices in implementation decisions -- data structures, use of standard libraries/interfaces, etc. If you did anything unexpected, did you comment it to explain why? (Maybe the hash table I would have expected would be completely wrong for some reason that you should explain to me.)

  • any reasonable, consistent style. I don't especially care how you order your members, name your methods/variables, or place your braces, but you should give the impression that you can follow a coding standard when we give you one.

  • documentation that actually helps. Note that "duh" comments count against you; that tells me that you're writing comments because you were told to write comments, not because you're thinking about the needs of the guy who'll have to revise this code in a year. You also lose points if your code contradicts your comments.

  • for object-oriented programming, reasonable decisions about inheritance, abstract methods, interfaces versus subclassing (if the language supports both), etc. Again, documentation helps here.

  • if you used any recognizable patterns (listener, factory, etc), did you use them in the expected way or explain why not?

  • evidence that you've thought about error conditions, exception handling, validating inputs (and when you don't need to), etc.

11

I wrote a blog article on the topic a while ago that might be useful to you in answering this question: The Code Sample

To summarize, as a hiring manager what I am looking for is this

  1. Can this person write maintainable code that is easy to read?
  2. Is this person still making rookie coding mistakes?
  3. Does this person write overly-complex/clever code? (this is a bad thing)
  4. Is this person telling the truth that they know the programming language(s) they claim on their resume?
  5. How well can this person communicate with me on requirements, and follow instructions?
1
  • +1 for "Understand that the code sample is used more often as a NEGATIVE differentiator than a positive one." Commented Jul 15, 2014 at 10:47
3

Employers are looking for code that is:

  • Readable. With names obvious so that functions 'read' like english.

  • Easy to change, small blocks, classes and methods.

  • Fun to work with.

3
  • This doesn't answer the question, which is what potential employers look for when asking candidates for code samples. Whether or not code is "good" as you've defined it in your answer is one of many factors for which code is reviewed. If you can put your answer in the greater context of the question asked, it would be much better.
    – jcmeloni
    Commented May 15, 2012 at 12:10
  • Good point. Done. Commented May 15, 2012 at 16:54
  • How do you know this? Do you conduct these reviews for your employer? Have you been a candidate and discussed this with prospective employers? Not challenging; just trying to establish where this info comes from. Commented May 15, 2012 at 17:03
2

I asked for code samples to see if they reflected organized thinking. After you view a variety of samples from a variety of people, it becomes very clear that some applicants can speak well on the topics, but produce undesirable code.

Another way I like to look at it: Would anyone hire an artist without ever having seen samples of their art?

0

When I was looking at hiring developers. After looking at the CVS and sorting them into 3 piles,

  • I would ask the top pile to submit a code sample.
  • Then I would give them a little project to do, which they had a week to do. (This was to see if they could garner resources by themselves to do it).
  • In the interview, I had a sample of obviously buggy code for them to find the bug.
  • I would ask them to write a small program such as a sort routine for an array of string.
  • I would name-drop common libraries to see if they actually had used them (not just heard about them).

For all of the code submitted, I was looking for

  • Style of code
  • Naming of identifiers
  • The absence of non-trivial inline strings and numbers
  • Readability
  • Existence of some comments
  • And I would ask them why they chose to do things a certain way.

It may sound unnecessary, but I have had these sorts of applicants (even though the advert had said a minimum of 3 years of experience)

  • A store manager who did not even own a desktop, never mind done any programming
  • A supposed developer who refused to do any programming task in front of me (Don't you trust me?. It's beneath me to prove to you that I can program!)
  • A data entry operator who thought they had been programming.
-3

Politely remind them that any code you wrote for your current or previous employer does not belong to you, and that it is not possible to provide a code sample.

Unless you worked alone on a significant chunk of code, you will also have the problem that you can't claim to have written all of it.

Showing them side projects might not be possible. Most companies will claim all ownership of code you write, even when done after hours. You would have to establish prior to employment that you will be working on these side projects, and consider them your IP not belonging to the company.

I can't imagine what a company will get from looking at code samples. Unless they are also provided the entire application, but they don't have the time to analyze how your code fits into the entire application. They will have different samples from each person they are interviewing. Each sample will not be comparable to the other applicants.

12
  • 5
    Regardless, more and more job agents, and interviewers seem to request code samples, and they seem to expect you to show part of the code you wrote on your last project. Politely reminding them that the code does not belong to me seems to result in my being passed up for the opportunity about 100% of the time.
    – Rac Main
    Commented May 15, 2012 at 4:39
  • 4
    A middle ground to the quandary is to provide code that you wrote as part of a hobby/personal need or you have contributed to the open source community. If you don't have one yet, it's never too late to start. It will be a lot of mileage for your application to demonstrate skill (your code/coding style), concern for the company's welfare (honoring Non-Disclosure or Confidentiality Agreements with former employees), and passion (contribution to the community/problem solving).
    – shimofuri
    Commented May 15, 2012 at 9:31
  • 3
    @JimInTexas: No, it means you enjoy doing things in your spare time that aren't coding. Things such as sports, film, theatre, art... A person can enjoy coding and solving challenging problems, but after 8 (or more) hours of it at work, many people like to do something different. Commented May 15, 2012 at 15:52
  • 2
    @Atif: How big or complex would think these code samples should be, if the purpose is to prove you can code? What should the nature of it be? What's to stop someone from grabbing a simple bit of code of the CodeProject, tweaking it slightly, and saying, "look I has made a code samplez"? Commented May 15, 2012 at 18:08
  • 6
    @FrustratedWithFormsDesigner, writing something on your own so you have a sample to show is the same principle as spending your own time to polish your resume -- you do your job hunting on your own time and this is part of that. It doesn't mean you have to spend every evening and weekend programming; it just means it may be advisable to spend one Sunday afternoon producing a good sample. If it's something you can then contribute to an open-source project, so much the better -- it wasn't just make-work and somebody benefitted. Commented May 16, 2012 at 14:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .