views:

1011

answers:

10

When I was learning to code, I read up on the design patterns like a good boy. Long after this, I started to actually understand them.

Design discussions such as those on this site constantly try to make the rules more and more general, which is good. But there is a line, over which it becomes over-analysis starts to feed off itself and as such I think begins to obfuscate the original point - for example the "What's Alternative to Singleton" post and the links contained therein.

http://stackoverflow.com/questions/1300655/whats-alternative-to-singleton

I say this having been asked in both interviews I’ve had over the last 2 weeks what a singleton is and what criticisms I have of it.

I have used it a few times for items such as user data (simple key-value eg. last file opened by this user) and logging (very common i'm sure). I've never ever used it just to have what is essentially global application data, as this is clearly stupid.

In the first interview, I reply that I have no criticisms of it. He seemed disappointed by this but as the job wasn’t really for me, I forgot about it.

In the next one, I was asked again and, as I wanted this job, I thought about it on the spot and made some objections, similar to those contained in the post linked to above (I suggested use of a factory or dependency injection instead). He seemed happy with this.

But my problem is that I have used the singleton without ever using it in this kind of stupid way, which I had to describe on the spot. Using it for global data and the like isn’t something I did then realised was stupid, or read was stupid so didn’t do, it was just something I knew was stupid from the start. Essentially I’m supposed to be able to think of ways of how to misuse a pattern in the interview? Which class of programmers can best answer this question? The best ones? The medium ones? I'm not sure....

And these were both bright guys. I read more than enough to get better at my job but had never actually bothered to seek out criticisms of the most simple of the design patterns like this one.

Do people think such questions are valid and that I ought to know the objections off by heart? Or that it is reasonable to be able to work out what other people who are missing the point would do on the fly? Or do you think I’m at least partially right that the question is too unsubtle and that the questions ought to be better thought out in order to make sure only good candidates can answer.

PS. Please don’t think I’m saying that I’m just so clever that I know everything automatically - I’ve learnt the hard way like everyone else. But avoiding global data is hardly revolutionary.

+4  A: 

I suppose they were trying to see how "senior" you are by asking what you do not like in your tool box. You start seeing disadvantages and problems after you have tried something and got burnt with it.

They may have wanted to see if you have opinion on things your work with. If you have no opinions, it could be that either you:

  • not senior enough yet
  • do not care enough about what you do
  • bored with this particular interview

As for design patterns themselves, I believe it was just an instrument. They could have picked up any other topic to see your reactions.

Developer Art
or how much have you learned from the seniority of others.
Stefano Borini
+1  A: 

I think the question is a fair one. If you have used the pattern and thought about why you were using it then it is likely that you may have seen a downside to it. If you copied some code off the web or from a book and just went on your way then you may not have. If I were interviewing someone, I would want to see that they have tried things out and thought about them.

Christian Pena
+4  A: 

In the same way as interviewees will be reciting stock answers to questions like this one, the interviewer might well be doing the same thing. I have a list of questions that I run through with candidates, many of these questions are easy, none of them are tricks, none of them particularly inventive.

Believe me, I've seen many candidates whose resume/CV looks stunning but, when confronted with relatively straightforward questions, just crumbled. By asking this question they are hoping to hear you talk about your experience - even if you just say what you've just written, that you've used them in a particular way but not another, you're helping them out. A good interviewer is listening to what you say and how you get there, not just for the stock answer on their sheet.

The difference between someone giving you a book answer and someone actively trying to describe their own thoughts and experiences is gratifyingly obvious.

Your first answer might have disappointed as you might not have seemed like you were trying to meet the interviewer halfway - why are you being asked the question? The questions might be better thought out, but the bad candidates will react worse than the good - and that's the key.

Unsliced
+1  A: 

I personally think that expecting people to talk about how they've misused design patterns is a bit silly. Like you said, you know, either from reading up on Singleton patterns, seeing other people's code that misuses a singleton, or just understanding intuitively that a singleton has the potential to be abused as a global data object, that a singleton shouldn't be used as a substitute for global data. Misusing a pattern yourself isn't necessary to understand that it can be misused.

Having said that however, I think it's equally silly not to 'play the game' so to speak. When you go in to an interview, the interviewer is looking for certain responses to his questions. It's your task, as someone who is trying to secure a job, to answer those questions truthfully and honestly, but to answer them in a way that the interviewer is looking for. I guess the thing to do now, is to own up to how bad of a software developer you are and how much you've messed up. Some people need to mess up a few times before they 'get it,' while others seem to just 'get it.' Personally, I'm in the former, you seem to be in the latter. The Catch-22 is, if you haven't misused a pattern because you've seen other people do misuse it, or you just 'get it,' and you say that, you come off as arrogant, and no one wants to hire that one arrogant guy who (in his own mind) never makes a mistake.

I agree with you, though: most interview questions I've been asked weren't very well thought-out, and didn't do a good job of separating the stellar candidates from everyone else. But wishing that people would ask better interview questions is like wishing that our bodies didn't age: you can't do anything about it. So smile, accept it, and answer the question the way the interviewer is looking for. The goal of an interview is to get them to make you an offer, right? So get them to make you an offer, and put yourself in a position to say no to them if you don't like them cause of their interview questions.

Hooray Im Helping
+1  A: 

Essentially I’m supposed to be able to think of ways of how to misuse a pattern in the interview?

No. You're supposed to demonstrate that you have a familiarity with a common current programming debate.

Which class of programmers can best answer this question? The best ones? The medium ones?

The ones who can trot out the stock reasons why Singleton Is Bad in the current consensus (in as much as there is one). The ones who own books about pattern use and misuse. The ones who read SO.

Which, though it may not be a fair test of actual programming ability in itself, seems a fairly reasonable thing to ask, to me.

bobince
A: 

Ok everyone, you're right I know. Just getting me talking about the reasons it is good and bad is justification enough I guess. There was just something that got my back up being asked the same question twice in two weeks, as if this was some kind of special short-cut to my programming knowledge.

And there is also to me something absurd (but also unavoidable) about developing a pattern as a solution to a problem, going on about it for ages in books and webistes, and then after a while going on about how many ways there are to misuse it.

This may just be progress. It may also just be fashion. i suspect it's the first but sometimes it's hard to tell....

A: 

I think I'd probably return with questions about what kinds of criticisms are wanted, e.g. where is it a bad idea to use the pattern, what limitations does one have to remember in using it, or some other variation. My goal is to see if I can get enough of a sense of where the question is trying to go to give a reasonable answer. Perhaps the interviewer is seeing how well you know where not to use something.

JB King
A: 

I think it was not about learning all about singleton by heart. Just remember how GoF was written. Authors got their experience and wrote about it for a long time.

So any pattern have info when it should be used it`s pros and cons. When reading it you are getting a theoretical level. When using patterns for years you are getting practical level. People who have practical level can describe their experience.

So I think question was asked to know how senior you are, so that you could share your experience, maybe you have your own that interviewer do not know and you could start sharing experience. That would be the best answer.

Yaroslav Yakovlev
A: 

i have an interview in three days and I can bet my life that they are going to ask me about the singleton pattern...and now after i've read some crap on the internet ....most of which i did not even understand(dependancy injection...wtf!!)....i am going to blurt out like things like a web browser!!!....lets see how it goes...thanks for raising the subject....

samyzee
A: 

You can read design pattern interview questions from the free PDF available at QuestPond.