Preparing for a code interview

iljitsch

Ars Tribunus Angusticlavius
9,637
Subscriptor++
As part of the interview process for a potential new job, I'll be going through a code interview. Although I do have a bachelor's degree in computer science and I've programmed in C and PHP over the years, I'm not a professional developer, I've only worked on relatively small projects on my own. (My bread and butter is networking.)

I recently had a look at Python, but I don't think it makes sense to interview using a language that I'm still learning. So I'll be interviewing using PHP.

My question: as PHP has an insane amount of built-in functions, how many of those would I be expected to use / be able to use in a code interview? I also tend to forget the order or arguments etc, so I would need to spend some time making sure I have those memorized for relevant functions, so I really need to know which functions are relevant and which aren't.

And I assume I'll have to practice my OOP, as I've never used object orientation in any of my projects in the past.

Any other tips are also welcome.
 
D

Deleted member 43669

Guest
The important thing is that the people interviewing you have a good measure of your experience. If your CV doesn't say you've been working professionally with PHP for 1-2 years, they shouldn't drill you for PHP minutiae.

An interview should be tailored to the candidate and position. I think a few details on the position would be useful. If this were an entry-level PHP coding position I'd probably...

* Algorithms... I think these are just useful to prove that a candidate can code minimally. Perhaps I'd ask stuff such as "how do you display an initial snippet of a post in a blog's front page?", "how would you validate an email address?" (that's a controversial one. If you told me "by sending an email there with a validation code I'd be happy, although I would be looking at a simplified check), "how do you turn URLs in a forum post into links", etc.

* "Real-world coding"... how to write a PHP page that displays the results of an SQL query, how to validate a form and insert/update data in a database...

But that really depends a lot of the position you are applying to...
 

iljitsch

Ars Tribunus Angusticlavius
9,637
Subscriptor++
The important thing is that the people interviewing you have a good measure of your experience. If your CV doesn't say you've been working professionally with PHP for 1-2 years, they shouldn't drill you for PHP minutiae.
Right, that makes sense.

Note that I'm not interviewing for a developer position, like I said, I do networking. However, this company, which I'll leave nameless, expects all their technical people to have some level of coding ability. (I'm expecting the code interview to be along the lines of the ones at Google or Amazon, although perhaps somewhat easier as I'm not interviewing for a developer position.)

There's a good amount of information out there on the type of problems that tend to come up in these interviews and the type algorithms and data structures you should know, but not so much on my specific question: how much of the language am I expected to be able to use without looking stuff up?

For instance, the recruiter mentioned as an example a problem where you have two tables in CSV files and you read those in memory and basically do an SQL join "manually" and outputting some combination of information from the two tables.

Now the obvious way to do that is with stuff like fgetcsv(). However, I have never used that function and even if I had, I wouldn't remember the exact arguments. So would I just roll my own, reading lines and splitting them on the commas? Or should I make sure I do know functions like fgetcsv and their arguments?
 
D

Deleted member 43669

Guest
Oh, I see.

The way I see things, that question is not about knowing the CSV parsing function for the language you are using. You should be able to say "I assume I can write read_csv(path) and get a list with a dict per row*". They might say "OK, there's a function in the stdlib which looks like that, move on" or they might want to drill into how to implement that function. However, I believe that question is about how to do the join. It's kinda a good question because the naive implementation can be whiteboarded quickly and then you can start discussing how efficient it is and how to make it more efficient (both faster or with less memory usage).

I have a sysadmin friend who moved into a more SRE position. I know he had to do a take-home coding exercise, but I have no idea whether he had an interview about coding (probably he did). They are more likely shooting for a guy who does systems *BUT* who can troubleshoot performance/reliability issues in production, which means needing to understand code and being able to reason about algorithms...

* yes I'm simplifying- returning a list means the entire CSV will be loaded in memory.
 

gregatron5

Ars Legatus Legionis
13,003
Subscriptor++
I agree with koala. With Java I can make reasonable assumptions like "You should know about the Collections library, what it contains (in concept) and how to use them," but I don't require you need to know every detail of it. Likewise, if I were to ask a similar question w.r.t. CSVs I would likely accept "I know there's a function that reads a file and returns a structure of this type. I don't remember the exact syntax, is it OK if I just pseudocode it in?" or "I know there's an Apache Commons library that does this, is it OK if I assume I can use something like that?"

Unfortunately (fortunately?), I don't know enough PHP to say what a good baseline would be. I'd personally look to be comfortable knowing how to do something that might be applicable to the job, like (just making this up) "Assume you have this data store for deployment configurations in something like Consul. The security team decides values which are URLs need to be https and the change was supposedly done in Consul. How would you make sure all the configurations have been updated?" That would require notionally knowing how to make a REST API call, parse JSON, loop through a dictionary (of dictionaries), check that all values that start with http actually have https.

"how would you validate an email address?" (that's a controversial one. If you told me "by sending an email there with a validation code I'd be happy, although I would be looking at a simplified check)
Lol it's almost HTML-like in well-formed vs. valid. /[^@]+@[^.]+\..+/ is about all you can do for well-formed. Valid requires the validation email.
 

Fruity Pebbles

Ars Praetorian
595
Subscriptor
The two companies I've worked for that did code interviews didn't use them to see how much of a particular language the candidate had memorized. If that's the situation you're going into I'd say that's a red flag and you should avoid that company.

Both situations I've been in used code interviews as an open-book problem solving exercise: Here's a description of a problem, here's an IDE and a web browser, go write some code. We judged candidates on stuff like whether they took a rational approach to the problem, with bonus points for actually coding a working solution; code design; code style; comprehension of the problem. For a lot - not all - of candidates this worked pretty well - we would get an idea quickly whether or not the candidate was comfortable attacking problems on their own, how much of the language they knew, whether or not they produced readable code, etc. A *big* part of the exercise was the review discussion afterward. If the candidate wrote crappy code but could explain what was crappy about it and what they'd do better with more time then that was a very good sign; if you gave the candidate leading questions about possible improvements and they gave you a blank look then that was not a good sign.
 

Ben_H

Ars Scholae Palatinae
1,059
The two companies I've worked for that did code interviews didn't use them to see how much of a particular language the candidate had memorized. If that's the situation you're going into I'd say that's a red flag and you should avoid that company.

Both situations I've been in used code interviews as an open-book problem solving exercise: Here's a description of a problem, here's an IDE and a web browser, go write some code. We judged candidates on stuff like whether they took a rational approach to the problem, with bonus points for actually coding a working solution; code design; code style; comprehension of the problem. For a lot - not all - of candidates this worked pretty well - we would get an idea quickly whether or not the candidate was comfortable attacking problems on their own, how much of the language they knew, whether or not they produced readable code, etc. A *big* part of the exercise was the review discussion afterward. If the candidate wrote crappy code but could explain what was crappy about it and what they'd do better with more time then that was a very good sign; if you gave the candidate leading questions about possible improvements and they gave you a blank look then that was not a good sign.
This post is quite helpful. Thanks!

I'm also preparing for potential coding interviews for software development roles, and it's so hard to tell these days what code interviews look like since in the past they were different. What you described sounds much more reasonable and relevant than the old Google or Amazon-style interview that entailed solving some obscure word problem on a whiteboard that seldom had real-world application and showed little about your actual abilities. Being able to reproduce a solution to the Towers of Hanoi problem doesn't really demonstrate that a person would be a good web developer compared to getting them to build a rudimentary website with certain features.
 
My question: as PHP has an insane amount of built-in functions, how many of those would I be expected to use / be able to use in a code interview? I also tend to forget the order or arguments etc, so I would need to spend some time making sure I have those memorized for relevant functions, so I really need to know which functions are relevant and which aren't.

Most of the coding questions I've seen or given don't rely on built-in functions - just loops, data types, arrays, string manipulation... Some, like FizzBuzz, continues to be useful because it weeds out a lot of applicants. For more complicated stuff - the value is in seeing how you think to break down the problem in order to solve it. For dedicated coding jobs, I have known outfits to use approaches like leetcode (where code has to be valid).

The interview is to see if you fit the position (and work culture). They'll grant you some leniency for stress, but things will be tailored to the position (not you). Infrastructure jobs/tasks can automated via shell scripting, so the coding bit makes sense.