Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Choosing a Programming Language for Interviews (codingforinterviews.com)
36 points by bcjordan on Feb 5, 2014 | hide | past | favorite | 44 comments


[deleted]


As a non-traditional programming language fan, I'd love to see candidates throwing up working solutions or providing code samples in any language they choose.

My co-workers, though, are a little more stuck in traditional thinking on this topic. Also, a number of them are programmers "by accident" and so have maybe picked up one or two imperative programming languages. Simply saying 'Haskell' or 'Lisp' or maybe even 'node.js' would make it impossible for them to make any kind of judgement on a candidate. You probably wouldn't even get an interview, but we are also fronted by a HR machine with a frightening array of check-boxes to navigate through.


Read in a file full of numbers, one number on each line

Represent those numbers as integers in your program

Replace each number with that number times its line number

Write the file out elsewhere

And complete the task right now at your computer as fast as possible, you’re being timed

Think—what language would you immediately reach for? Do you start your experimentation with ipython, or irb? Do you pop open Eclipse and write some Java? Or create a new .cpp file?

I have 13 years of experience leading teams in building and designing web applications in a wide variety of languages and platforms - some pretty big ones, too.

I would not be able to do this in any language without looking at the API.

And they wonder why "It's so hard to find good people!"


I've been interviewing a fair bit lately, and I just really struggle with what you say above. To me if you can't write that simple program in some language without looking at an API or consulting Google at every turn, it feels like you haven't used the language enough (either that, or the problem isn't in a domain your familiar with, but you can usually tell which it is pretty quickly).

I don't deduct points for not getting the syntax precisely, but if they don't know the very basics of "open()" and "for line in file" and "int()", but say they have 3 years Python experience, I'm thinking No Hire.


And that's where we disagree. I think this whole "FizzBuzz" craze is as equally stupid as the riddle craze was.

My brain, right now, is working on a way to pop messages off of a RabbitMQ queue onto a clustered pool of Akka workers while minimizing the duplication of work and avoiding race conditions in the output.

My career experience is in Java with a sprinkling of Python. I honestly cannot recall off the top of my head the I/O Api to do that task. Let alone on a whiteboard or in some shared google doc.

Hm, I need to open a file. OK, no problem - new java.io.File(path). Er, wait, I remember there's a FileReader. Probably should use that. Do I need a File first? Or can I just give FileReader the path? Ah, shit - I need to read each line. I think that's a BufferedReader. How do I get from a FileReader to a BufferedReader? Is it constructor param? Wait, maybe FileReader _IS_A_ BufferedReader.

So, I 'fail' the interview with you. Maybe your company has a need for someone who can write a 10 line script that can read a file line by line without having to look at the API while being timed. In that case, yes, you probably have weeded out a bad candidate.


It's surprisingly easy to make it a long time without needing to read from a file. If you're writing web apps, you almost never read directly from a file; all of the input comes from a database or HTTP requests.


What about

     * Libraries for reading arbitrary size integers

     * and for computing with arbitrary size integers

     * Efficiently handling files larger than RAM

     * Error handling when the file is not as promised?
Should an interviewee just have all those APIs memorized in advance? Even in this age when reading an unformatted text file is so far from common?


In some ways it's more of a system admin/ops task than a 'programmer' one.

    #!/usr/bin/python
    import sys
    with open(sys.argv[1]) as f:
        for l, i in enumerate(f):
            print l * int(i)
We keep MD5 file lists of all files we archive to tape before we delete them. Today one of our editors found some footage, and we needed to know if those files had been archived already. It was a couple lines of bash, and then a 10 line python script.

I can write this kind of thing with my eyes shut.

You need problems like this, but also big architectural ones to really get an idea where someone is at.


I'd probably reach for node.js for something like this...

    var fs = require('fs');
    var lines = fs.readFileSync('./somefile.txt','utf8')
      .trim().split(/\r\n|\r|\n/g);
    for (var i=0; i<lines.length; i++) {
      lines[i] = i * +lines[i];
    }
    fs.writeFileSync(
      './outfile.txt'
      ,'urf8'
      ,lines.join('\n')
    );
Easy peasy. That's off the top of my head so fs syntax may not be correct. I'd probably give it a quick run through in the node repl to start with.

Why JS, I find that this type of scenario begs for a language that does coercion well... say what you will about JS, it does do that.


Really, that's easy peasy? Looks terrible to a Python programmer. :-)

   with open('input') as fin, open('output', 'w') as fout:
       for line_num, line in enumerate(fin, 1):
           fout.write('{0}\n'.format(int(line) * line_num))


I would've went with Haskell myself ;)

    main :: IO ()
    main = writeListAsLines . toDoubleList . lines =<< readFile "nums.txt"
           where
             toDoubleList y = zipWith (*) (map read y) [1..length y]
             writeListAsLines z =  writeFile "output.txt" (concat $ intersperse "\n" $ map show z)


I think you would really enjoy learning some other languages. You obviously understand programming concepts really well... but, node.js for this? really? Even C is less verbose than that JS...:

    #include <stdio.h>
    int main(void){
        unsigned int lineno=0;
        char line[1000];
        unsigned int number;

        while (fgets(line, 999, stdin)) {
            sscanf(line, "%u", &number);
            printf("%u\n", number * lineno++);
        }
        return(0);
    }
which reads stdin, and writes to stdout.

I'm sure the C may not be perfect, I've not really used it in years. Node for a task like this is a bit like using a Nimitz Class Aircraft Carrier to hammer in a nail...


stdin/out for node.js

    var i=0
        ,stream = require("stream")
        ,rl = require('readline').createInterface({
            input: process.stdin
            ,output: new stream.Writable() 
        });
    rl.on('line',function(line){
        process.stdout.write(((+line || 0) * ++i) + '\n');
    });
    process.stdin.resume();
I actually know several languages... ;-) Just find that node is my go to tool these days.


"leading teams" is very different from "coding 80 hours a week"

IDEs like Visual Studio and Idea will show you classes, methods and parameters as you type. You only need to know which namespace to use for a given operation.


Do people actually have interviews where they're required to read in a file? I would figure in this world, especially where most of our information is from a database, this type of code is either abstracted away or written in one or two places.

In the interviews I've been in, none of them required that I load information from a file, usually I only wrote the function that did the real (algorithmic) work. Only one of them required me to write code that compiled; and that was a SQL question.

Even TopCoder doesn't require you to "read a file full of numbers"


I would normally have to look it up on google or within my existing code base.

But, I still think its a good idea to refresh yourself on stuff like this before hand, because in an interview:

- you don't need the mental distraction from the real problem.

- you're always under time pressure.

- it's never a positive, if you don't know something.


Read a repetitively formatted text file line by line and do something relatively simple with it? It's just begging to be done with awk.

awk '{print $0 * NR}' fileOfNumbers > output

I did use > to dump the output to file. Should that count as bash-fu?


  nl input | sed -e 's/$/*p/' | dc > output


Has anyone had the luxury of using multiple languages in an interview?

E.g., "Oh, you want me to twiddle bits? Let's do this in C.", "Oh, now doing silly text file stuff? Ruby.", "Write a simple properties thingy? Javascript.", "Find all permutations of blah? Lisp or Scala."

I wonder how common that is.


For my current position interview, there were several code samples I needed to write. One of the requirements was that I had to use two different programming languages (although I could pick which one for which sample).


I was recently job hunting and chose to do coding problems in python when possible, even though I have 7+ years C# experience. For the first interview it got me into trouble because I actually didn't know how to read args from the command line and didn't have access to the internet! For all my other interviews (mostly Java jobs), I'm glad I used python for the simple reason that solutions tend to require a lot less boilerplate code than C#. I typically have to erase/change a couple lines as I'm solving a coding problem and using a terse language helps reduce this distraction. I don't think the interviewers minded and in one case I think using python gave me some (undeserved) mystique.


This reminds me about that saying: 'There are three kinds of lies: lies, damned lies, and statistics.'

According to the table about relative popularity of programming languages, Javascript (5.2%) and C# (5%) have only 5 times the popularity of Scala (1%) and Haskell (1.2%). In most contexts, this data is just wrong.

This just proves that unless you know or show the underlying method and context, quoting statistical summaries is almost completely pointless in trying to enhance your point.

I realize that this is probably being a bit pedantic as that graphic is hardly the main point of the article however it does tend to place a question mark over the rest of the article when a seemingly dishonest bit of data is used to help prop up other points.


It specifically says:

Consider this great visualization of the most popular coding languages of 2013 from the interactive practice problem website CodeEval:


The table is about relative self-reported popularity of languages to write answers to interview questions in, not to develop production code.


A follow-up question for interviewers lurking here on HN:

What are your thoughts about candidates who code correct solutions in a language not in use at your workplace?

I have a nagging feeling that some positions in my group have gone unfilled due to tech stack mismatches in candidates who were probably perfectly capable (or better) coders, but were most recently working in other tech stacks. Considering these types of candidates seems to be challenging in my workplace.


I happily and successfully hire people who don't speak the language(s) we use, but use languages in the same general area. I've shied away from hiring people who have no experience in the area at all. For instance, I'll hire within (Java, C#, C++, Objective C) reasonably happily (and that's not a complete list), or (Python, Perl, Ruby, Lua, JS) fairly happily (with a special callout for JS to distinguish between "JS but only in the browser" and "actually knows JS", the former not necessarily counting as knowing how to program at all), but I hesitate to hire if you have no experience in the target cluster.

I think it's a big mistake to avoid hiring a Python programmer because they don't know Ruby, but it's one people seem happy to make, even in otherwise relatively enlightened organizations.


Unless you rely on a whole tightly coupled environment, like .NET+WCF, or some enterprise Java solutions and the question is based on them - the language in the answer shouldn't matter. If the candidate knows more than one language, they can learn more. Unless you need some specific framework/library knowledge, the rest is just syntax. And that's the least important part of programming.

Exception: first jobs and very inexperienced people. Basically if the answer is given in a specific language because they don't know any other and couldn't produce the answer you want after short time of studying relevant docs, then it may be a real problem.


The only real difference I see is whether or not I personally know my way around the language in use. If I don't know much about it (Haskell comes to mind), I have the candidate explain how to read the code. Doesn't happen often frankly, but I find it quite interesting, also gives me insight into how well I can understand stuff the candidate is explaining.

I suppose the only thing that would make me frown is if the candidate was evidently a huge language zealot and wanted to use nothing but their language of choice. But I've never interviewed such a person actually.


I don't place much importance on the language used, but then my team uses a bunch of different programming languages because we integrate existing systems more than we write new ones from scratch. However, I do think the language choice itself says a lot about the person. If they reach for C, they're probably more interested in systems programming. If they reach for Ruby, they're probably more interested in web app development. If they reach for Bash, they're probably interested in SysAdmin-type work. Does their language choice reflect an interest in the job they're applying for? If it's reasonable to expect the person to know multiple languages well (i.e. they're not doing their first internship in college or something) I also want to see them pick an appropriate tool for the job. What I'm really looking for, is if the language they know best is actually a language they know well. If it's not, that's a red flag to me. I wouldn't say it's bad to do an interview in C# when applying for a job at a Java shop, but all other things being equal, using Java would be better, IMO.


For general roles, it's a question of how much you are willing to invest in a candidate before he/she starts producing. Big firms like Google/MS/Amazon are willing to hire strong candidates who aren't familiar with a given stack. A young startup might (understandably) not be able to pay someone for a few months to ramp up on a stack that's not familiar to the candidate.


That is subtly wrong, because there are really two things there: there is the language itself, and there is what has already been built with it. Say you get a really strong Perl guy, but you use Python. At a startup, he just has to learn the language. At a big company, he has to learn the language and the last decade's worth of codebase.


You are missing the point - startups don't always have the time/money to train someone in a new language. That's why they are looking for Javascript Ninjas who can hit the ground running. Established firms inherently have money to invest in training if they choose to.


If you have hired the right person they will very quickly "train" themselves and the only cost to you will be a slightly slower start (which will resolve itself in days to a couple of weeks max) at producing real code.

Well worth it if the alternative is hiring someone who knows the language/framework you're working in, but pretty much only knows that language/framework.


I always try to interview in Python, because I can bang out complicated ideas quickly with very minimal boilerplate.

Writing in Python can be almost like writing in pseudocode.


I switched to using Python from Java for coding interviews and it almost felt like cheating. List comprehensions and the like don't necessarily trivialize many interview problems, but they certainly make them much quicker to solve.


I can see why you feel it's cheating, but I think it's simply using the right tool for the job -- instead of worrying about which headers to include and what the exact C++ type specification for a map iterator is ... in Python, you can think about the actual problem at hand, rather than arcana.


Python is the most popular language at 30% in 2014? I've worked for a lot of big corporations and interviewed at hundreds more over the last few years. Not a single one used Python in any way, shape or form.

Maybe that's changing, but I find it hard to believe.


Define big corporations? I am sure C++ and Java are still the most widely used in big corporations.


Best Buy, United Health Group, Target, Medtronic. And I agree with you, I thought C++ and Java were more widely used than Python. The graph at the middle of the page in the article indicated Python was the most popular language at 30+%.


The main issue in the blog post is about "you, interviewee, which PL to use for coding interview" and the statistics OP uses is about what PL people uses on CodeEval (which is a place people go on to challenge themselves).

So you are right about the doubt. Simply put, a lot of interviews tend to be fixed. Interviewees don't get to choose the PL to use during coding session. It is usually fixed. If you are interviewing for Java software engineer candidate, then coding in Python makes no sense. So that statistics does not reflect reality. It's merely to say that "Python and Ruby alike PL" are popular should the candidate has the right to choose a PL.


I tend towards python simply because most interviews are done on whiteboards, and python is a very concise language, which means I can average more logic per handwriting effort than I can with something like Java.


Or... Have people use whatever they want so long as they are able to communicate their ideas, and move the focus to ensuring that they understand how software development works. You can teach syntax much more easily than you can train someone to think like a programmer.


If I had this option during an interview, opt not a language, rather the idea to solve a problem described in Abstract Syntax Tree. This usually ends up in a pseudo code with parens.


So, Lisp?


As a candidate, always use python.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: