in

Nikola Malovic

.NET development and architecture
VusCode - Coding dreams since 1998

TwitterCounter for @malovicn Add to Google Reader or Homepage Add to Pageflakes Subscribe in Bloglines Add to Technorati Favorites View Nikola Malovic's profile on LinkedIn

VusCode - Coding dreams since 1998!

.NET exploration, articles, cool links, surf logs, book reviews, .net, c#, smart clients, software factories, patterns & practices, web casts and much more

Asking the right questions while interviewing developers

Just another fizzbuzz interview question

I really hate interviews regardless on which side of the table I am sitting during them(Ok, it is a bit easier when you interview candidates :) )

One of the main reasons why I hate them is the stupidity of the programming trivia and questions being usually asked: all sorts of binary tree related traversals, converting numbers from one base to another, number sequences  etc… I mean, who really cares about that stuff in everyday's work?? Am I applying for mathematician job or for a developer one?
I have a feeling those questions are created to fresh grads because they don’t have much real world experiences but that’s just me guessing..,

But, not all of the interview questions are stupid and the most famous example of what I find to be a good type of interview question is famous “fizzbuzz problem” described by Jeff Atwood and Scott Hanselman which is an example of very simple task which resolution is purely related on persons real-world like thinking skills and not related at all to any other type of knowledge.

Couple of years ago I’ve stumbled on a video recording of a session made by Brad Adams regarding his excellent Framework Design Guidelines book where he mentioned an example which looked so trivial to me that I quickly discarded it as very obvious to literally everyone. (I couldn’t find that link for this blog post :()

Couple of months after that I was interviewing a candidate for one senior position and due to the fact he gave fuzzy answers making me wondering if he gets heap and stack so I took Brad’s example idea and came out with a simple question looking something like this

namespace InterviewTrivia
{    
	public class ClassA    
	{        
		public override string ToString()        
		{            
			return "Hello from class A";        
		}    
	}    
	
	public class ClassB : ClassA    
	{        
		public override string ToString()        
		{            
			return "Hello from class B";        
		}    
	}    
	
	public class ClassC : ClassB    
	{        
		public override string ToString()        
		{            
			return "Hello from class C";        
		}    
	}
}

Nothing fancy here just 3 classes inheriting from each other and each one overriding object ToString() method

Now the console application Program class can be done something like this:

using System;
namespace InterviewTrivia
{
	class Program
	{        
		static void Main(string[] args)        
		{            
			ClassA first = new ClassC();                        
			ClassC second = new ClassC();            
			ClassB third = (ClassB)second;            
			ClassA fourth = (ClassA)third;            
			object fifth = (object)fourth;            
			
			Console.WriteLine("1: " + first.ToString());            
			Console.WriteLine("2: " + second.ToString());            
			Console.WriteLine("3: " + third.ToString());            
			Console.WriteLine("4: " + fourth.ToString());            
			Console.WriteLine("5: " + fifth.ToString());            
			Console.ReadLine();        
		}    
	}
}

As you can see there, first 5 lines are doing different variants of casting class c instance and then printing out the result of ToString() method.

I wrote this sample on a whiteboard (to avoid having R# helping him with the answer) and ask the candidate what would be the resulting output of an app.

Why is this fizzbuzz question?

Because it is:

  • very simple problem and code sample
  • focused on concrete programming scenario pinpointing the (IMHO) important OOP concepts which need to be understood by senior developers
  • in order to solve it one doesn’t need any knowledge other then programming skills.
  • it is white board friendly – very important attribute for DEV interviews

So, what happened?

To my surprise that candidate bluntly failed the test reporting as a result:

  1. “Hello from ClassA”
  2. “Hello from ClassC”
  3. “Hello from ClassB”
  4. “Hello from ClassA”
  5. “InterviewTrivia.ClassA”

I was done with the interview convinced this candidate was exceptionally bad and I’ve stayed convinced in that until accidentally I’ve run the same sample with couple of other developers and in most cases got the same answer as the candidate gave. That fact is maybe just the result that we .NET developers are really spoiled and allowed to be blissfully ignorant about how stack and heap in .NET works (which is btw the thing I strongly disagree), but that is not the point of this blog post.

The point is that with properly chosen trivia and programming questions we are using in interviews we can avoid loosing good candidates just because they don’t know for sure how to convert –1234.56 to hexadecimal base number (even on paper) and focus on getting information on really important attributes a new member of the team would be bringing to the team (or not) once joining the company.

(Sample code of today’s post can be found here)

Technorati Tags: ,,
Share this post :
Published Jan 07 2010, 11:52 PM by malovicn
Filed under: ,

Comments

 

DotNetKicks.com said:

You've been kicked (a good thing) - Trackback from DotNetKicks.com

January 8, 2010 1:02 AM
 

DotNetShoutout said:

Thank you for submitting this cool story - Trackback from DotNetShoutout

January 8, 2010 3:28 AM
 

Sergey Shelukhin said:

You have an error (copy paste artifact?), line 20 should say "fifth".

January 8, 2010 10:05 AM
 

Twitter Trackbacks for Asking the right questions while interviewing developers - VusCode - Coding dreams since 1998! [vuscode.com] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Asking the right questions while interviewing developers - VusCode - Coding dreams since 1998!         [vuscode.com]        on Topsy.com

January 8, 2010 11:04 AM
 

malovicn said:

Sergey, corrected!

Thanks for the tip

January 8, 2010 1:37 PM
 

Jason said:

I believe this has more to do with issues around virtual than stack/heap.

Since methods are not virtual by default in .Net, I'm not surprised to see developers answering as if ToString were not virtual.  For that reason I think a hint would be in order just to jog memories.

Still, thanks for this question, I'll be using it with my candidates.

January 23, 2010 10:34 PM
 

Nikola Malovic said:

Jason,

I agree that this can be answered from HOW c# point of view (understending how virtual works) or from WHY stack\heap point (realizing that all we do is creating multiple pointers on stack pointing to the same heap object) and that is also a nice extra info to get from candidate regarding how involved he is in achieving crafstaman level :)

January 28, 2010 3:19 PM
 

Andrea Fringe said:

I am not a programmer, just out of curiosity, what would be the result?

February 2, 2010 9:21 AM
 

Pavel Korshikov said:

Actually nor I, developer with more than 20 years experience cannot easily answer, because actually it doesn't matter. (Or we have to differentiate programmers and developers?)

Because most of mine time is architecture debates, selecting right solution and configuring. To see what will happens when someone overload some method - it is not actual for current development process at all.

For mine personal opinion most important is capability of candidate to choose good solution that can be implemented in specified time and as related process candidate's experience.

February 19, 2010 2:33 PM
 

malovicn said:

Andrea,

The result would be 5 times "Hello from class C" because there are two instances of class C on the heap and 5 stack pointers of different type to that two instances.

In other words, it is the heap type which matters not the type of pointer on stack.

Pavel,

I understand what are you saying - I've been doing the high level stuff myself for years but that sounds to me more like an architect then like a developer area of responsibilitty and I agree there are different sets of questions to ask in that context (I guess, what I call a developer is what you call programmer I guess).

As II said this question is (IMHO) of fizzbuzz type so you can ask it during the short phone screening before real interview etc...

IMHO, even in managed world understanding of principles of memory allocations, garbage collector mechanism etc is essential for senior+ developers\programers because sooner or later would be required in debuging memory leaks, tuning up performance etc...

I might be wrong in expecting this , but as I said - just my oppinion :)

February 23, 2010 10:17 AM

Leave a Comment

(required)  
(optional)
(required)  

Enter the numbers above:
Add

Powered by Community Server (Non-Commercial Edition), by Telligent Systems NAVRCHOLU.cz