Stupid Interview Questions · 10 March 2010

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 *cool*.

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. wink

Edit: A software developer and blogger in Japan (Yasushi Aoki) generously offered to translate this article into Japanese. Thanks to his effort, you can now find Stupid Interview Questions — Japanese translation on his website.
日本語版はこちら

-- David --

...

Poem: "London Trees" · 15 December 2009

I signed up for NaNoWriMo again this year — my third time — and as before, I did not finish. However, this is the first time I felt that I quit for a good reason. I had a plot outline constructed, and characters, and scenes, and my writing was clicking along quite well (averaging about 2000 words/hour, give or take). A few days into the month, though, I realized something: the writing of my novel had transformed from an exercise in writing the novel itself into an exercise in writing — in terrific detail — about all of the art I would rather have been doing instead of writing. I decided that it would be a much more productive, not to mention enjoyable, use of my time to actually just do the art I was really wanting to do, instead of writing about the doing of that art.
Anyway, the title of the novel I had started working on, “For Our Own Destruction Weep,” was taken from a poem by Kathleen Raine. Here is that poem (you can find it, along with many other excellent works, in Kathleen Raine’s Collected Poems, available at Amazon and other sources).

London Trees

Out of the roads of London springs the forest,
Over and underworld, the veritable Eden
Here we have planted for our solitude,
Those planes, where thoughts unblamed among the leaves may run.

Sensing us, the trees tremble in their sleep,
The living leaves recoil before our fires.
Baring to us war-charred and broken branches,
And seeing theirs, we for our own destruction weep.

And women, sore at heart, trying to pray
Unravel the young buds with anxious fingers
Searching for God, who has gone far away,
Yet still at evening in the green world lingers.

Obedient still the toiling trees
Lift up their fountains, where still waters rise
Upwards into life, filled from the surrounding skies
To quench the sorrows thirsting in the world’s eyes.

— Kathleen Raine

-- David --

...

Survey: Are you House or Wilson? [Survey ended] · 28 October 2009

Survey’s over! The most popular choice was…well, see for yourself:



-- David --

...

"WingStreet" Slogan: Terrifying? · 8 October 2009

Am I the only person in whom the slogan of Pizza Hut’s “WingStreet®,” viz. “You Are Now Entering Wingfinity!” induces a sense of dissociated terror? Every time I encounter said phrase, my mind irrepressibly spins off into an imagined universe of meat, bones, and sauce, swirling about in a postmodern space-time goulash. I’m then forced to consider the composition of such a carniverse — what fills the meatus, so to speak, of the meat, in which visitors must presumably subsist? Are we, by “entering Wingfinity,” condemned to immediate death by drowning in 8 bold sauces? Does the carniverse still have, or need, dark matter, given the filling of space by the saucy, cleft rudimentary flight appendages? Where are all the chickens?

-- David --

...

Online dating: sample first contact letter (statistically AWESOME) · 22 September 2009

Background: OKCupid recently published a blog post, “Online Dating Advice: Exactly What To Say In A First Message.” I recommend reading that first wink.

How’s it going?

I noticed that you mention your favorite movies in your profile, and they’re pretty much awesome, LOL. Your good taste in cool video games is also fascinating!
Anyway, my name is Zeus, and I’m in a metal band called “Vegetarian Zombie Physics.” I’m an atheist — I noticed you didn’t mention your religion in your profile, so I’m kinda curious what you think about it (sorry if that’s too personal, no offense intended).
Anyway, I hope I hear from you, though I understand you’re probably pretty busy and may take a while to get back to me (this online meeting thing is so awkward sometimes!). I’ve got to get back to grad school now. Take care!

P.S. What’s your name?

-- David --

...

OLE DB fun: Mute IErrorInfo and date-time parameter overflow. · 22 September 2009

Here's some useful, hard-won info.

Scenario:

Course of action:

  1. The first things to look at are the status codes for each parameter (you _are_ using status codes, I hope!). If you see that one or more of the parameter status codes are DBSTATUS_E_UNAVAILABLE (i.e., "8"), that says that those particular parameters were not the cause of the error, and you can disregard those.
  2. Look for the parameters that have a _different_ error code. If you find a parameter that has a datetime type (DBTIMESTAMP on the OLE DB side, datetime on the SQL Server side, may not extend to other DBMSs), and it is marked DBSTATUS_E_DATAOVERFLOW, this means that the DBTIMESTAMP has a value that is not within the range of the datetime value, to wit: 1753 A.D. to 9999 A.D. So, for example, if you start out with an empty filetime, which has a range dating from 1601 A.D., and you stuff it into a DBTIMESTAMP value, you will end up with this overflow error.

-- David Pickett --

...

The Top 10 List of Numbers. Srsly! · 21 August 2009

Feel free to argue with me in the comments. I bet you’re wrong, though.

  1. 3
  2. 2
  3. π (that’s “pi” in case your browser or eyesight are insufficient…as mine were)
  4. 5
  5. 42
  6. i
  7. 0
  8. 1
  9. ϕ (phi)
  10. 108

Related around the web:

-- David --

...

Capsule Music Review: Godspeed You Black Emperor! · 13 August 2009


Godspeed You Black Emperor! supplies the soundtrack to modern life — your fading hopes, your crumbling dreams, your encroaching madness, the dissolution of your soul. This is the sound of your spiritual death. This is the song of apocalypse.

 

-- David --

...

When I Was A Rapper Wannabe... · 12 August 2009

Back when I was more optimistic about my ability to do everything (aka “insane”), I considered taking up rapping. Go ahead, get it out of your system. I’ll wait.

Anyway. Here are two snippets (unscored):

Titanium Coder

I write for x64, I write for Itanium
Your code is like tissue, mine is like titanium.

You put in one feature, I slip in three,
You hire all your testers — mine work for free.

Other MCs claim they can write code.
Yeah, right, motherfucker, just hit the road.

Rhyme Dragon

You wanna step to me?
Just keep on braggin’

I got titanium ribs,
I’m like a motherfuckin’ dragon.

I’ll tear out your heart
And swallow it whole;

Crack open your skull
And swallow your soul.

On the remote chance anyone wants to use them for something, they’re Copyright © 2007-2009, David A. Pickett, and hereby released under Creative Commons Attribution (“by”) license — attribute by annotating the above copyright information and/or linking back to this page.

-- David --

...

Read This Post Later, When You Go "WTH is this blog about, anyway?" · 11 August 2009


I write a whole friggin’ lot of blog posts. Most of them never make the leap between mind and internet, or paper and internet, or even draft and live. This is partially because I like to post well-crafted, thoughtful articles, partially because I usually forget that I wrote something down somewhere to post, and partially because I’m too busy writing down another blog-post-to-be.


The side effect, of course, is that I hardly ever actually post anything on my blog. This is a real shame, I think, and I’m going to do what I can to fix it. Mostly I’m going to do this by going through some of my dozens of notebooks and posting what I already wrote down at some point to go onto the blog. I’m going to restrain myself from putting in hours per post, because I don’t want to spend that much time on it, so they’ll probably be, in general, rougher than in the past.

I’m not terribly worried about confusing the regular readers of my blog, because if someone actually reads my blog regularly, he or she is likely already confused. I haven’t actually done the numbers on this, but something like 99.5% of my traffic comes from search engines anyway, so maybe some of the stuff I post will turn out useful for those lost souls out there googling madly for The Answer.

Content is, as they say, king. I’m going to lift my scrap 2×4 scepter, hitch up my flannel robe, and climb onto a duct-taped hammered-tin throne.

-- David --

...

Previous