views:

1810

answers:

9

I have an interest in particularly odd yet relevant questions to root out guys who claim to have several years in a particular programming language.

Since I know C best, I'll start with one of my favorites:

Is it possible (other than branching into the twilight zone) for a function to return more often than it is called?

You guys should be able to find other ones better than this one. Any language is fair game: pick your best one.

EDIT: for those of you who don't know what branching into the twilight zone means, it is a low-level jump resulting from mishandling code pointers.

+32  A: 

Is this a good interview question or a good trivia question?

I tend to think that language corner cases are not a good way to determine if someone is smart and gets things done.

Steve Rowe
That's my opinion.
Paul Nathan
Vote++. There are exceptions (some of Andrei Alexandrescu's code comes to mind, since he was truly pushing the limits of C++), but for the most part IMHO good programmers avoid odd language corner cases because it's unnecessary complexity and brittleness.
dsimcha
+1 : esoteric knowledge != productivity. good trivia, truly terrible interview.
nailitdown
HE just wants to root out guys who claim to have lots of experience with a particular language. I think this is a fair thing to assess, even if you don't put too much emphasis on them giving perfect answers... just to make sure their eyes don't glaze over, and they don't look clueless.
Alex Baranosky
hear, hear - this is an interview anti-pattern
annakata
A: 

Could one use a goto to jump into the function again?

You can't use goto for that. Even if you could, where would the function return to?
Greg Hewgill
In C, that won't compile. The equivalent ASM is usually pretty darn close to what is considered branching into the twilight zone.
Joshua
+3  A: 

This is terrible interview question, knowing or not knowing the question offers no bearing on someone's competence as a programmer or software developer.

I would think it is possible with a setjmp?

EDIT

Ok looks like you can't longjmp into a function that has already returned as the stack has unwound and is invalid. In that case I don't know how it could happen.

Isn't that "branching into the twilight zone"?
chaos
Pretty close to the twilight zone; using setjmp() and longjmp() is not something I do with relish (or frequently).
Jonathan Leffler
BTW, setjmp is such a function.
Joshua
A: 

Not in the limits of the C programming language. But if you're willing to do assembly on function pointers and manipulate them directly, I suspect so, yes.

The best edge case I ran into was that structs in g++ 3 don't call destructors/constructors. That was a bad, bad, boo-boo that tripped me up a few years ago.

Paul Nathan
A: 

C# / .net specific:

When should I use IDisposable on a class? When should I call it?

Do I need to null a reference after a call to IDisposable (hint* this is a trick question).

If your programmers can't answer this your in trouble.

Spence
So what's the answer... When do you need to call IDisposable, if you are using using statments?
Alex Baranosky
Answer: you don't! That's what using is for!
Alex Baranosky
You can't always use a using statement. Sometimes your object's constructor will fail and you need to catch before the finally to ensure it disposes. Or you have specific things you need to do.
Spence
+11  A: 

I actually decided NOT to take a job where the interview were questions like that .... It just signaled to me that they were not interested too much on the ability to solve problems...

It's a good question for prospects to rule out employers.

(BTW I actually knew the answers to mine, although I don't know this one)

webclimber
+13  A: 

In my books a good interview rarely if ever follows the "trivial once you've heard the answer, nearly impossible if you haven't" pattern.

What I consider fair game:

1 - Foundation of cs / math / core concepts of candidates preferred language.

Do you know your cs concepts(algo, data structures, etc), math and common syntax?

2 - Using the principles from part 1 can you solve straightforward problems?

Choose appropriate algorithms and data structures for a real-world problem. Create an efficient algorithm to solve a tangible problem. Solve a somewhat challenging math proof with assistance only on specific formulas. Code something on the order of FizzBuzz.

3 - You're allowed one "widowmaker". Usually math or algorithm design. A question you don't expect people to be able to answer. See how they deal with it, bonus points if they solve it. If they're on the right track, great. If they give an honest effort, but are way off that's ok. If they get defensive or freeze up, bad.

4 - All questions must be dry-run in interview conditions on several current staff members before use in a real interview.

Questions seem a lot easier when you know the answer. Test them on staffers who haven't heard the problems before, see how well they do.

Avoid trivia... and this is a particularly bad trivia question for an interview. It's obscure, and a definitive no answer would be impossible to prove. I've worked with C for years, and I'd have to answer "not in any of the code I've worked with or written, and not in any situation I can think of".

patros
I like the idea of dry running the questions first.
Steve Rowe
You've got a point. Better to throw him a few hard questions from the core of CS. If he passes, it doesn't matter if his resume lies.
Joshua
+6  A: 

For someone claiming expert C/C++ status:

What is the value of

2["hello"]

and why?

If someone can explain that in a couple of sentences then they've definitely mastered pointers, and as Joel expounds at length that's a good thing to know.

Mark Harrison
That would be 'l', wouldn't it?
Graeme Perrow
That would be "World" :-)
chikak
Can someone explain this please? kthxbai.
mrduclaw
@mrduclaw, a[i] is defined as *(a+i). So, it goes like this: a[i] == *(a+i) == *(i+a) == i[a]. so, 2["hello"] == "hello"[2] = 'l'.
Mark Harrison
A: 

Yes it's possible and especially with C, it does work with one special function

multicoredump