views:

522

answers:

7

I've been interviewing a lot of .NET programmers lately and I haven't met one that knows what IDisposable is or what it is used for. Is it really unreasonable to expect someone with 4-6 years experience to know that?

+8  A: 

I wouldn't think so. If you don't understand what IDisposable is, how can you appropriately understand when to use a using statement?

My guess would be that a lot of people know to put certain code in using statements, but don't know why which is rather scary.

Kevin
Cargo cult programming happens everywhere. We shouldn't really be surprised it happens with .NET too.
Oded
Oh don't get me wrong, I'm not surprised by it. It just gets a little harrowing at times when you look at code and have to ask yourself "Did they really mean to do this, or was this done, because they didn't know not to do it?"
Kevin
@Oded, I had to LOL - not a lot of people know what a cargo cult is...
code4life
+1: I knew a developer who didn't know what IDisposable was for, but he had using statements all over his code. When I asked him why he just said 'CodeRush makes a squiggly if I don't put it there'.
SnOrfus
+2  A: 

I'm quite surprised that the knowledge of IDisposable is too low. Whenever you have a resource that must be closed, and you don't use the using statement, you have to use IDisposable.

Maurizio Reginelli
Actually, you have to use a class that *implements* IDisposable. And since most every disposable i've ever seen or used disposes itself in its finalizer, it's possible to forget to Dispose() it, never notice, and have no problems.
cHao
+27  A: 

Nope, sorry. If they don't know IDisposable, they don't understand object lifetime in .NET, so it's safe to assume that they have no idea how GC works. For someone who claims 4-6 year experience, he's either a "drag-and-drop" developer, or a liar. Either way, no hire.

hmemcpy
Well, he could have the same first year experience 4-6 times :)
Kevin
@Kevin: you hit the nail on the head. A lot of programmers get by for many years without ever learning any more than they need to know to write working (but badly written) software.
Charles
+2  A: 

Having just had a job interview today I wish I had been asked a question like that! All programmers should know about IDisposable. It's arguably the most important interface to understand because of the using statement.

I find it unthinkable that a programmer with 4-6 years experience doesn't know about this.

David Neale
+4  A: 

I would expect developers with that level of experience to know IDisposable. However, it is a complex subject, if you want to dig into all the details. Joe Duffy wrote a rather elaborate post on the subject some years ago. I wouldn't expect all developers to be able to cover all the gory details in that post.

Brian Rasmussen
I'm just talking about a basic understanding, I would agree that you shouldn't necessarily be able to talk about Duffy's post in an interview context.
Jonathan Allen
+1  A: 

Yes, it is unreasonable. Few programmers that are college age level + 3 to 5 years (the always preferred candidate) have ever written pure Win32 code to know what an "unmanaged resource" looks like. It doesn't typically ever come up in their college years, Java is the teaching language nowadays, a language that doesn't have the same pattern.

There are a large number of .NET programmers that have written .NET code for years and shipped production code without ever disposing anything. I'd recommend other interview questions:

  • Why does Java not need the IDisposable pattern?
  • Why do .NET programmers get away with never disposing anything?

That tests for insight rather than rote programming. Perhaps more appropriate for the second interview?

Hans Passant
I'll grant that a developer whose primary experience comes from other languages may not have run across IDisposable, but that also means they're **not** (yet) a competent .NET developer. Whether or not that should be used as hiring criteria is a totally different subject.Anyone claiming to have "years" of experience with .NET who doesn't understand the basics of garbage collection, especially when applying for .NET jobs, has a very surface level understanding of .NET. Therefore, they are either exaggerating their experience, or likely aren't the quality developer Jonathan seeks.
hemp
I hire candidates that have the innate horse sense to know how to translate a real life problem into an algorithm. The booky knowledge is never a problem, easily covered by a code review. Horse sense and experience are weakly connected.
Hans Passant
A .NET programmer who has never used dispose would also be a programmer who has never dealt with database or file access. Both of those are a definite no-hire where I work.
Jonathan Allen
@Jonathan: unfortunately that's not true. There's no shortage of production .Net code out there which uses database connections and file access and doesn't have `Dispose()` or `using` in sight. And you know what? Those programs may be leaky, but otherwise they work fine.
Charles
+8  A: 

It's not unreasonable to expect somebody to understand IDisposable, but I've also noticed that here on Stack Overflow, IDisposable-themed questions are second only to Linq questions in terms of their frequency of occurrence. It's plainly obvious that far too few programmers truly understand everything they should about this, and I'm honestly not sure why; it can't be that they're all unqualified, I think it's just that there's too little education on it.

For those of us who came from Delphi or C++ and have had to do manual resource management in the past, this is blindingly obvious, but for people who learned in Java or Python or even VB, not so much. And you'll never get a compiler warning if you forget to Dispose an object; if you're self-taught as far as .NET programming goes, you could easily go for years without realizing that it's actually a problem.

So with that in mind, I wouldn't immediately fail somebody in an interview if they didn't understand the meaning and proper usage of IDisposable, but I would consider it a red flag, like so many other things. It's not nearly as bad as (for example) not knowing how to traverse a tree structure or being unable to write FizzBuzz.

I think it's a good question to ask, and if somebody had never heard of it before, I would probably give a very quick explanation and then ask a follow-up question: "The .NET Garbage Collector can only manage memory. IDisposable lets you explicitly free other kinds of resources. Can you think of any resources that would fall into this category?" If they can't answer that question either, then I'd be worried, because it would indicate ignorance not only of a specific interface in the .NET Framework but of resource management in general. Even if you were taught Java in school, you ought to understand that you need to close files and connections that you open.

Another red flag, perhaps an even bigger one, is if somebody says that you need to put every IDisposable in a using block but can't explain why or list any exceptions to the rule (i.e. factory methods). That's worse to me because it could be an indication of cargo-cult programming tendencies.

So keep asking the question, but maybe temper your responses. Don't end the interview immediately if somebody can't answer it. Consider that a .NET programmer never actually has to learn this in order to write functioning (albeit buggy) software.

Aaronaught