Assuming this candidate was interviewing for a software developer position, then the question is relevant, otherwise not.
However the question does have a couple of problems:
- I would not expect anybody to come up with a good answer on the spot. As a developer you sometimes come across a piece of code which you like, and that can be either some of your own or something that somebody else wrote. But it is very rare to see code so likable that you remember it a few weeks later.
- The candidate may not even be allowed to show you that piece of code due to confidentiality or copyright.
Assuming you ask the candidate this question as preparation for an interview and they have a few days to come up with an answer, then they might come up with something.
Chances are they will come back with whatever code they happened to look at during those days, which best fit the criteria. They might very well be in a position that most of the code they work with is confidential, and the only code they could show you is any open source code which happen to be part of the platform they are working with.
There is nothing wrong with that per se, but they might not look at enough different pieces of such code during that time to have some really nice samples to choose from. The real problem with picking a piece of code that way is, that the reason the developer took a look at the actual code of the platform likely was that they had a problem with it. That means the selection will be biased towards poor quality code.
Overall I think the answer to the question is not going to tell you a lot. Even if they managed to come up with a likable piece of open source code, then it still won't tell you much because they might as well have had somebody help them answer the question.
Where you might get useful information from the candidate is from follow up questions. Of course the candidate will expect you to ask what they like about this particular piece of code and have a prepared answer for that. So unless you can challenge their idea on why this is a particular likable piece of code, then you have learned nothing.
The responses you mention in your question are however too negative. Here is why I think so.
I'd up and leave if asked that!
Anybody overreacting like that to a single question they don't like is not the kind of employee you want anyway.
How is that relevant?
If a programmer can't tell a good piece of code from a bad piece of code, then he isn't very competent. I expect all good developers to feel pleased when reading a well written piece of code.
This is just stupid!
No, the question is not stupid. But problematic because it cannot be answered on the spot, and you won't learn a lot from a prepared answer.
Leave it, he isn't supposed to be obsessed with his code
Would you hire an employee for his experience, if he has never done a piece of work which he is proud of?
If someone "likes" his code, he should go see the doctor
If a developer has never written a piece of code which he would feel pleased to read at a later time, it can mean one of two things.
- He is not very good at writing code.
- He has been unfortunate enough to only work on projects where corners had to be cut on every piece of code he wrote.
Either way I pity those developers who haven't written one piece of code which they like.
Similar questions which can work well
You choose a piece of code and let the candidate comment on it. Maybe even give them two pieces of code and ask them which they like better (the catch being that one piece is stylish but buggy and the other is not very well formatted but happens to work correctly).
Ask them about code they have developed and are proud of, but don't ask them to show the code instead talk about the design.