Last week at the MIT January term course Hacking a Technical Interview, after a class period finished a student asked me the question:
I know many different programming languages. How do I choose which one to use during my interview?
Why choose just one?
Don’t get me wrong—I advocate learning and writing code in many programming languages. But when it comes time for programming interview preparation, I feel it’s important to choose one language to focus your prep on and get to know it very well.
While many interviewers don’t mind you writing pseudocode during the early planning step of answering a question, others I’ve come across really want you to show you can write compilable code without an IDE. Not only that, but that you appear very comfortable writing real code.
Now back to our polyglot student—how might they approach choosing just one?
If you’re fresh out of school and throughout your college career you were instructed in Java, C or C++, stick with what you know.
Imagine this: what if I asked you right now, at your computer, to please, using a programming language (not your bash-fu or vimscript):
- 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?
Ideally you’re most comfortable with a language that your interviewer has used before, but at the very least it should be readable by a wide audience.
Consider this great visualization of the most popular coding languages of 2013 from the interactive practice problem website CodeEval:
If you’re using a non-standard feature of your language that might not show up in others (dense Python list comprehensions, Ruby functional programming techniques, higher-order functions)—it’s a good idea to be cognizant of the interviewer’s comfort with the language and gently offer explanations of concepts they might not have exposure to yet.
Some advice from the book Programming Interviews Exposed—all things equal, bias slightly towards the language your target companies use if it’s one of the ones you’re most comfortable with.
For example, if the company you’re applying to is primarily a Ruby shop and you’re fairly confident with your Ruby, go with that. If you’re applying to a low-level hardware manufacturer working mostly in C and Assembly, go with that. Game company that uses ActionScript, and you’re writing a game in it now? Go with that.
Here are some oft-used languages at various companies as reported in Cracking the Coding Interview and on Quora:
- Facebook: PHP, C++, Python, Java, Perl. High regard for dynamic/scripting languages. (source)
- Microsoft: C++, C#, Java, Python (source 1, 2)
Excellent, so you’ve chosen a language to focus your preparation on and to use for your interviews. Now what do you do?
When you are doing practice problems, try to always write with the language you’ll be using in your interview.
The couple of weeks leading up to your interview, when you’re doing personal projects and hacking on things for fun, try to use that language as well.
Make sure you have at least the following operations down pat:
- Initializing and using hash-backed maps (dictionaries) and sets
- Performing queue and stack operations (whether using an array, like with Ruby’s pop/shift, or an explicit standard library implementation like Java’s Stack and Linked List-backed Queue classes)
- Defining classes with constructors and attributes, static and instance methods, and defining a subclass and interface
- Throwing exceptions for (1) invalid input and (2) custom messages
- Iterating through arrays and dictionaries (both key and values)—including iterating while maintaining an index (Ruby’s each_with_index, Python’s enumerate)
- Casting between strings and integers
- Strings: get character at index, get range, concatenate
- Initializing 2d arrays
- Arithmetic: modulus (remainder), division (if the first operand is an integer, will it round the result to an integer?), rounding (ceiling and floor)
- (Bonus) Switch statements
- (Bonus) Built-in language sorting. Quickly defining a comparator to sort an array.
- (More advanced candidates) The 5 standard bit manipulation operations (L/R shifts, not, or, and, xor)
Especially if the company you’re applying to has experience with your language, it can be helpful to brush up on the best practices for your language. Sometimes you’ll get trivia questions, or be asked about some language-specific patterns.
If you’re going with Java, for example, and applying to Amazon, where Java is heavily used, consider reading through some of the best practices material.
Some classic “technical chit-chat” interview questions are:
- What do you like about language X?
- What don’t you like about it?
- How does it compare to (another language you profess to know)? Similarities/differences?
Formulating some smart opinions about your language is generally a good idea.
Where does your language fall among the different programming language paradigms? A book like Seven Languages in Seven Weeks is a good starting point if your breadth of language paradigm understanding is lacking.
Now you’ve got your language and some steps to take to know it better for your interviews. Go forth and prosper!
Of course, as noted earlier, it’s not necessary to always stick to one language when not preparing for interviews—learning new languages is fun and can lead you to understand your go-to language better. But the week or few days before your interview, be sure to drill deep into one.
What is Coding for Interviews?
Each week, Coding for Interviews members receive two things:
- A programming interview question
- A distilled computer science topic review (with silly gifs)
You send in your answer and the next week we review solutions.
We practice a little bit each week. The idea is, the next time our group members are looking for jobs, we will be prepared.
New group members are always welcome!
One email each week. No spam. Easy unsubscribe.