in reply to Re: Evil Interview Questions
in thread Evil Interview Questions
I wouldn't do that, therefore that code is suspect.
Those two were the map vs. for and return 11 unless shift...
I also avoid map in void context (it clashes with my concept of map). Until recently, I'd have rewritten the map into the for without another thought. Now I know that there is a difference between them, if and only if the context is important to what's happening in the block. I don't expect I'd run into that case often, but I do expect I'd spend a long time figuring out what had happened if I did (and didn't already know the answer to this question).
I've seen the simple return $x unless $y construct come up a couple times here, and there are probably more. I suspect it gets written into "real" code inadvertently. I think it's a good thing to be able to recognize. Yes, it needs a rewrite, but you have to know what it does to be sure you haven't broken anything after that.
The last one is just plain unimportant.
I wondered if the candidate knew that for my $x turns $x into an alias for each item. I agree this wasn't a very good question; it's my least favorite out of the bunch.
|
|---|