168

In my experience, managers and even employees at a potential employer tend to emphasize the commitment to quality in their company or their team during interviews. I am also routinely asked about my proficiency with tools and processes to improve and maintain code quality. It is also customary to write some code during the interview or as an assignment.

Having experience with several maintenance projects, I had to learn the value of good code the hard way. It has become very important to me when writing my own code. And I do not want to be employed by a company that is not committed to writing good code, definitions of good code aside.

However, once the legacy code is on the table I am often disappointed as it turns out that the commitment to code quality is rather a figure of speech. It tends to be teeming with simple errors that have been introduced years ago, has no consistent formatting, no consistent idioms and sometimes exhibits a grotesque misunderstanding of basic coding techniques and principles. I am probably preaching to the choir here :)

Is it a good idea to ask a potential employer to show some source code first? Specifically, I would like to see some production code samples.

How can I ask for it so that a potential employer will understand my concerns and actually allow me to take a look.

Are they likely to refuse on grounds other than bad code quality (confidentiality etc.)?

If they should refuse, how can we reach an agreement that is satisfactory for both sides?

For the sake of the argument, let's assume that I will be able to determine the code quality from a fairly small sample - my question is really only about whether and how to ask for it. Warning me about low expected returns is nice, but off-topic.

I am not an applicant. I have been approached because of my qualifications and would like to evaluate whether I am actually interested. I am not afraid of being excluded from the race. My primary objective is to find out if the food is to my liking without having to eat up the whole plate.

Peter Mortensen
  • 1,003
  • 1
  • 8
  • 8
kostja
  • 1,671
  • 2
  • 14
  • 15

13 Answers13

149

It is highly unlikely that they are going to provide you with a sample of the code, so really what you need to figure out is how you can answer your questions without seeing the code. You're trying to make sure that they value good coding practices, so ask them about that.

Here are some example questions that should help you understand how much value the company puts on maintaining quality code over time. There are plenty of other things that you can ask specific to your situation and priorities.

  • What sort of source control do you use?
  • How does the team report bugs?
  • Do you conduct peer reviews on code?
  • How do you ensure that code written by one developer will be easy to read and understand by another?
  • How do you maintain legacy code over time?
  • How do you keep your team members up-to-date on the best coding practices and techniques?
  • Do you use any static analysis tools, such as Checkstyle, to enforce coding standards? (@Ryan)
  • How long is your code freeze before a release? (@Sandra Walters)
  • What is your test framework? (@m24p)
  • At what point in development did you start implementing good coding practices? (@dotancohen)

EDIT:

Some folks are pointing out that just because the interviewer tells you something, doesn't mean it's entirely true. Their standards for peer review may not match yours, or maybe the manager doesn't know as much about their team's coding practices as they think. This is true of everything you are told at an interview, across all topics, and you have to rely on trust at a certain point. If you really would feel more comfortable seeing some code, then by all means, ask! I just don't think you can presume the answer will be yes.

David K
  • 30,066
  • 21
  • 108
  • 140
  • 4
    +1 Makes perfect sense. I think I will start by asking the questions you have proposed and only ask for code if the reaction is evasive/startled/mumbling. – kostja Sep 24 '14 at 13:39
  • 3
    To add on to the list of questions to ask, I would ask about any static analysis tools or any tools that automate the process of enforcing a coding standard. I know Java has Checkstyle. – Shaz Sep 24 '14 at 16:35
  • 15
    Hmm, during an actual interview I have asked to see some code of non essential parts of the application and been shown it. I simply saw it as part of 'getting to know the company'. This was already at the point though that the company knew they wanted me, and I was likely to accept. – David Mulder Sep 25 '14 at 06:17
  • 1
    +1. A small sample of code won't tell you much out of context. Whether the codebase as a whole is good or not will be heavily influenced by whether the whole development process is conducive to producing good code. – Fiora the Ferret Sep 25 '14 at 08:31
  • 6
    Also to this list I'd add the question How long is your code freeze before a release? If the answer is none or a very short one, then it may be a shop that is practicing protoduction... and the ensuing hilarity of fixing bugs with the recently-released product. – SWalters Sep 25 '14 at 15:55
  • 3
    They could be doing all of those, and afterwards you can find a page full of gotos in the core of the C++ application. There's really no certain way to assess the team skills (or company's for smaller scenarios) without working on them. – Marco A. Sep 25 '14 at 23:04
  • 3
    On thing I asked when interviewing with potential employers was "what is your test framework"?

    If I didn't hear about automated unit tests etc, it was not a good sign.

    Another good generic question is ones that force the interviewer to say something negative about the company. Usually you'll find a pattern that tells you something useful. If code health is an issue, someone might mention it.

    – m24p Sep 26 '14 at 20:56
  • I think you missed one key question: What are the steps in the build - test cycle and how long does it take? – kevin cline Sep 26 '14 at 22:00
  • 1
    "Do you have any automated processes, such as building and running tests?" Essentially, ask about continuous integration practices. – jpmc26 Sep 27 '14 at 03:28
  • 2
    I was at an interview once where they showed me the live code without even asking. Was no big deal. – TMOTTM Sep 27 '14 at 06:47
  • 12
    In addition to these questions, don't forget to ask at what point in development did they start implementing good coding practices. I've seen a lot of developers and companies mention coding practices, but when the code is a mess they answer, "Oh, that! That was written before blah blah blah". Of course, that consists of 90% of the code base. – dotancohen Sep 28 '14 at 17:57
  • "Also to this list I'd add the question How long is your code freeze before a release?". IMO the need to have a code freeze at all is a red flag. They're not necessary if your code is well tested and deployments are all fully automated – tddmonkey Dec 01 '20 at 13:23
27

If you are maintaining code, you might as well assume that the code you are maintaining will be structurally deficient in some way.

  1. Asking for code to review is no good because that code is considered confidential and proprietary unless it has been Open Sourced. You could take a look at the Open Sourced code but if it's well written and well structured, there is no guarantee that the legacy code is as well written and structured.

  2. Even if you were allowed to see some proprietary code, there is no guarantee that this code is not actually their best foot forward.

  3. If you were interviewing with me and you ask to see some of our proprietary code, I'll take the attitude that you don't know the meaning of the words "confidential" and "proprietary" and pass you over as a candidate. Why should I hire you anyway, if I have to worry about which legacy code you are willing to maintain?

Vietnhi Phuvan
  • 72,342
  • 8
  • 133
  • 268
  • 3
  • Also, if they actually allow you to see a sample of their code there is no guarantee that the rest of the code has the same quality/structure.
  • – trrrrrrm Sep 24 '14 at 11:06
  • 3
    @Vietnhi Thank you for your answer, Vietnhi. I agree with your points 1 and 2. There are no guarantees, but this is not relevant to the question. I am not afraid of being rejected - the company expressed their interest quite clearly. I am asking for a way to assess whether I should be interested as well. Do you happen to have advice on that? – kostja Sep 24 '14 at 11:19
  • 5
    @kostja At the end of the day, accepting a job offer boils down to a crap shoot where you hope for the best. If you are specifically hired to work on new projects starting from scratch, then you will not be running into legacy code. At least at first. Junior programmers get hired to maintain legacy code so that the senior programmers get to jump in on the fun projects :) During the interview, you can ask if you are expected to be deployed on the new projects starting from scratch or the legacy ones. A new project that includes a lot of legacy code does not count as a new project :) – Vietnhi Phuvan Sep 24 '14 at 11:36
  • 10
  • is pointless: if they want, they can show you. And showing a couple of file from a whole project won't undermine anything, it's not like you can make any use of them.
  • – o0'. Sep 24 '14 at 12:34
  • 5
    Adding to what @Lohoris wrote: let alone in a few minutes of looking at it, which is likely what it would be about if you asked about it on-site. If you ask to have it sent to you, that obviously changes things somewhat, but not by that much; the company can certainly pick some portion of the code which is less critical and/or doesn't do anything important. I could pull some code out of a larger system that is trivial in many aspects, but still gets the overall style of the code in that system across to the reader. I assume that's what the OP is looking for. – user Sep 24 '14 at 13:27
  • 1
    @ra_htial Your point 4 is exactly the same as the answer's point 2. – David Richerby Sep 24 '14 at 14:02
  • 13
    That is a very illustrative answer. This kind of reaction to a good question is a clear show stopper for me. I think I would quit the interview right after the 3rd point and leave you alone with your shitcode. – Slava Sep 25 '14 at 11:06
  • 7
    "Why should I hire you anyway, if I have to worry about which legacy code you are willing to maintain?" Well, isn't that the point? If you're only willing to hire somebody who is happy to maintain crappy legacy code, then that presumably means that maintaining crappy legacy code is part of the job description which means that kostja doesn't want to work for you. That's the whole point of asking! – Ben Aaronson Sep 25 '14 at 15:43
  • @BenAronson There is crappy code everywhere. Feel free to get out of the business. – Vietnhi Phuvan Sep 25 '14 at 15:50
  • 1
    The first sentence is terribly true: if you're hired for maintainability reasons don't expect great code in the first place – Marco A. Sep 25 '14 at 23:06
  • 2
    This answer by Vietnhi is negative and doesn't accept that varying degrees of code exist, varying degrees of maintenance exist, or assist the OP in determining whether it's a "reasonable" or "poor" situation at this company. – Thomas W Sep 26 '14 at 04:02
  • @VietnhiPhuvan -- and please read mhoran's answer below, http://workplace.stackexchange.com/a/34137/25730 to see what a real answer to this admittedly not-easy question is. – Thomas W Sep 26 '14 at 04:04
  • @ThomasW And since you just contradicted points 1 and 2 of my answer, you need to work on your reading comprehension. I am taking your patronizing very badly. – Vietnhi Phuvan Sep 26 '14 at 04:21
  • 1
    @ThomasW mhoran_psprep's advice on contracting is sound in that a contractor should know what he is going to work on before he even thinks of bidding - but that's feel-good advice: the contractor has no way to know that the code he'll be working on two weeks after the trial period - whether that code is any good. The analogy with home improvement contracting is false: a home and its issues are visible to a home improvement contractor. Not so with legacy code: the code contractor is taking a leap of faith based on the rest of the code based on the code that he has been allowed to see. – Vietnhi Phuvan Sep 26 '14 at 04:40
  • 5
    It's the employer's responsibility to recognize that they're actually hiring someone to refactor a mountain of shit, not maintain a code base. The employer needs to be up front about that, and seek a candidate who is both willing and able to do that kind of work. The attitude expressed in this answer would be self-defeating to the employer, because they would most likely end up with an employee who would immediately quit upon seeing the code, a sleazy yes-man who would take their money for nothing, or some earnest rookie who would only make things worse. – The Merry Misanthrope Sep 27 '14 at 15:06
  • 1
    The question wasn't about asking for unrestricted access to the whole codebase. With only a few minutes of supervised access to a small portion of the codebase, even someone with a photographic memory would be hard pressed to get something they could use maliciously. – Kevin Mills Sep 28 '14 at 21:29