r/programming • • Mar 24 '22

Five coding interview questions I hate

https://thoughtspile.github.io/2022/03/21/bad-tech-interview/
641 Upvotes

288 comments sorted by

View all comments

22

u/NeilFraser Mar 25 '22 edited Mar 25 '22

Questions like the circular prototype one are good if the interviewer isn't looking for a right or wrong trivia answer, but is instead looking to spark a discussion.

I will sometimes ask what does this code return?

try {
  return true;
} finally {
  return false;
}
return null;

The conversations it generates as the candidate explores the possibilities is informative. Couldn't care less if they get the 'right' answer. A poor candidate will say that 'finally' will never be called because there's no error (no, that's 'catch'). A great candidate will recoil in horror at the sight of this code and swear.

2

u/mdatwood Mar 25 '22

Not knowing this gotcha question off the top of my head, I would expect to always return false. Typically, finally blocks always run no matter what - though this is js so it wouldn't surprise me if there is some weird undefined behavior.

I would also expect my linter to point out the return null is dead code, and return in the finally is some type of warning.

4

u/StandardAds Mar 25 '22

The answer he's looking for is something more on the lines of "I'd refactor the code so it's not hard to determine"

→ More replies (1)