Stupid Interview Questions · Wed May 17, 12:38 PM
I was reading a blog post on some guy’s programming interview, where he complained about being asked to write a file copy function. Now, while it’s quite possible to take umbrage at this, if I were in that situation, I’d see it as a chance for some free entertainment
.
Q. What do you mean by “copy”?
A. Ummm…copy the contents of the file to a new file.
Q. What about the date/time stamps?
A. No, those don’t need to be copied.
Q. Does the result file have to have the same name?
A. No.
Q. Can it have the same name?
A. Umm…no.
Q. Do I have to worry about name spoofing? What about the Turkish I?
A. Don’t worry about that.
Q. Does it have to be in the same location? Note that if it is in the same location, it (probably) can’t have the same name. Unless you copy it to itself (another question…).
A. Yes.
Q. What about the attributes?
A. Make the attributes the same.
Q. Should I modify the attributes of the source file? If this file copy is part of a backup or archive operation, it’d probably be a mistake to leave the ‘Archive’ attribute on.
A. No, leave them as-is.
Q. What if the source file has the Archive attribute off? If I make it off on the new file as well, it could screw up the user’s backup software.
A. Just make it the same. I don’t care about the user’s backup software.
Q. Well, I’m not sure that’s the best approach to take when thinking about designing software FOR users, but if you say so.
A. ...
Q. What about compression? It’s a file attribute, but the copy destination may not support compression.
A. Don’t compress the copy.
Q. Even if the source is compressed, and the destination supports compression?
A. YES.
Q. What about encryption? What if the source file is encrypted, but the destination does not support encryption?
A. Don’t encrypt the copy if the destination doesn’t support it.
Q. Mmmmm, sorry, don’t mean to digress, but…that could be a serious security hole. Especially if wherever this file copy function ends up supports arbitrary parameters (directly or indirectly).
A. Look, just copy the damn file.
Q. What about the file creator?
A. Don’t care.
Q. What about the file owner?
A. Don’t care.
Q. What about file permissions? Is there a separate way we should handle inherited permissions and assigned permissions?
A. Forget the permissions.
Q. What operating system will this function be required to run on?
A. Windows XP.
Q. Home, or Pro, or Media Center, or one or more?
A. Pro.
Q. What service pack level are we aiming for?
A. Service Pack 2.
Q. Does that mean we don’t have to support any other SP level?
A. Yes, fine.
Q. How will the source file name be supplied?
A. As a parameter.
Q. Is it going to be supplied as a null-terminated string, a counted string, or an object?
A. Null-terminated string.
Q. Is it possible that a NULL pointer will be passed in?
A. No.
Q. Is it possible that an empty string will be passed in?
A. No.
Q. Is it possible that a malformed string will be passed in (e.g., no NULL terminator)?
A. No.
Q. What encoding will the filename be in?
A. Unicode.
Q. Sorry, umm…Unicode is not an encoding, really. If we’re using Unicode data, it has to have a specific encoding, like UTF-8, UCS-2, UTF-16, etc.
A. Fine. Make it UTF-8.
Q. OK. I’d like to note at this point that it’s a bit of a pain to have to transcode UTF-8 to UTF-16 in order to be able to supply it to Windows API calls.
A. Fine! UTF-16!
Q. Big-endian or little-endian?
A. ARGH. Whichever you want!
Q. Should we accept relative paths, or only fully-specified paths?
A. Only full paths.
Q. Are there any characteristics of the paths we are supposed to accept that I can screen the parameters on?
A. No. The caller will do all screening of paths and file names.
Q. How will the destination file name be generated or supplied?
...
Q. Am I required to support (or allow) an asynchronous copy operation?
A. No.
Q. How should I report errors? Exceptions? Error codes?
A. Whatever.
Q. Should I try and handle exceptions from called functions internally, or let them pass through to the caller?
A. Err…let them pass through.
Q. What if the destination file already exists?
A. It won’t.
Q. So the caller ensures that?
A. Right, sure.
Q. So if it does exist, I can just terminate the program, then? Obviously this would be a violation of preconditions, and who knows WHAT is going on.
A. Sure, whatever you want.
Q. What about alternate data streams?
A. Do whatever you want!
Q. Look, I’m sorry if you feel put-upon here, please don’t get hostile. I’m just trying to get a clear picture of the specs I need here. Obviously if I’m going to write a file copy method, instead of using one of the many extant file copy routines in various libraries and frameworks, it’s going to be fulfilling a specialized set of requirements, and I’m going to need to have good answers for these questions. If you want, I can hack something together in a minute, but I’d have to note that there were many unresolved issues as to requirements and purposes.
A. AIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
Mission accomplished. ![]()
...
Exold
You are my hero, Dave. :)
— Steve C. Wednesday May 17, 2006 #
bravo!
— wakka Thursday May 18, 2006 #
frickin’ hilarious.
— alex Thursday May 18, 2006 #
Mission Acomplished indeed.
— jivanov Thursday May 18, 2006 #
You forgot about sparse files :D
— Ringding Thursday May 18, 2006 #
That was covered under the ”...” ;).
— David Thursday May 18, 2006 #
the real question is, could you come up with all of those questions on the fly? how many rough drafts prior to posting? how many times did you phone-a-friend? is that your final answer?
— alex Thursday May 18, 2006 #
LOL…actually I did come up with almost all of those on the fly. I confess to having “cheated” a bit for the compression and encryption nuggets (I looked at the docs for the Win32 CopyFileEx function). The rest were entirely off the top of my head.
— David Thursday May 18, 2006 #
A good interviewer would have been looking for an answer like yours.
— Joel Spolsky Thursday May 18, 2006 #
A good interviewer would have been looking for someone less self-satisfied. (But I’m no Joel Spolsky, mind you.)
— Mortimer N. Cobblepop Thursday May 18, 2006 #
good job :D
— Pedro Thursday May 18, 2006 #
I would be very impressed if the candidate asked all those questions – someone who can think and handle the “what-if’s” is more than worth their weight. Good stuff.
— Paul Norrie Thursday May 18, 2006 #
Windows doesn’t use utf-16. It uses ucs-2. No hire!
— asdasd Thursday May 18, 2006 #
I used to think that too. I have it on good authority that that is not the case, though (see, for example, http://technet2.microsoft.com/WindowsServer/en/Library/6a13ac7d-e981-4c02-98f6-2476a034ab631033.mspx?mfr=true, http://www.jbrowse.com/text/charsets.html, http://blogs.msdn.com/oldnewthing/archive/2005/03/08/389527.aspx, http://www.answers.com/topic/unicode, http://www.microsoft.com/globaldev/getWR/steps/wrg_codepage.mspx, http://icu.sourceforge.net/userguide/codepageConverters.html, http://www.unicode.org/faq/utf_bom.html, http://www.unicode.org/notes/tn12/, and http://en.wikipedia.org/wiki/UTF-16).
— David Thursday May 18, 2006 #
Superb!
— ch00k Friday May 19, 2006 #
You forgot NTFS multiple streams. ;)
— Julian Birch Friday May 19, 2006 #
Actually, no you didn’t. Sorry!
— Julian Birch Friday May 19, 2006 #
I have interviewed thousands of people. I probably would have hired you after asking one more question: “Do you do this every time?”
Because that could be annoying. :D
— Moon Friday May 19, 2006 #
Would you like to be our new PM?
— Alex Saturday May 20, 2006 #
In case anyone happens across this and is interested in a related discussion, there’s one over at Reddit.
— David Saturday May 20, 2006 #
I’ve been meaning to write something about those irritating logic puzzles for a while so this was a good excues.
Interview by under-constrained programming
— Kirit Thursday May 25, 2006 #
I find someone with the Nom de Plume of “Mortimer N. Cobblepop” calling someone self satisfied to be amazingly hillarious. If I am wrong and that is in fact your Nom de For Reals, then I am very, very, very sorry.
I found the discussion over at Reddit great because out of the 29 people responding only 3 seemed to realize this post was funny.— ravencha Thursday May 25, 2006 #
Re UTF-16 vs UCS-2, the most relevant points are in the Unicode FAQ and a comment in Raymond’s blog entry
It’s slightly blurred as the ISO standard regarding UCS-2 has undergone revisions since then, but in most cases those classic meanings hold.
— Random Reader Sunday May 28, 2006 #
You may have been able to answer all your questions in one fell swoop by simply asking how the routine would be used. What is its purpose? If you know that, you can answer the questions yourself (and probably better than your interviewer, too).
— Adam Tuesday June 13, 2006 #
Wow! Some of the arrogant responses on that blog page blew me away!
As a team lead, I interview folks and always want some sort of representation of their ability. Sometimes I ask logic questions, sometimes I have them draw on the whiteboard, sometimes I ask them to write code on paper (syntax errors forgivable), and sometimes I show them a piece of broken code and ask where the problem is because I want problem solvers.
The responses, especially from recent graduates looking for internships are prime examples of why our industry is in the shape it’s in right now… arrogance.
p.s. I did like the response from the person who mentioned showing off i.e. error handling… that person is hired.
— Jeff Wednesday June 14, 2006 #
as a PM im not really into skill sets but on the ability to think and learn fast. So i would ask the applicant to learn a new programming language (not on his/her current skill set) in a limited time and ask he/she comes up with a simple program. eg: file copy :)
— godie Tuesday June 20, 2006 #