chris carter's web log

Home |  Contact |  Admin
 

RE:Technical Interviews

Posted on June 22, 2008      3 Comment(s)

My response to Hussain's post on Technical Interviews.(read it first and come back here).

Crazy Questions

I never liked that "...can you fit your hand..." question.  It's abstract-ish but has an answer.

I've seen some ridiculous microsoft questions(eg, "What would you do if you were to meet the Prince of Darkness?"), but they are intended to get you to show your creativity and thought process, there is no actual answer.

An interview for a technical position ideally would be conducted by the people that the individual fulfilling the position would have to interact.  The interview questions slash activities are driven by the job description  and the candidate themselves.

The Technical Interview

There are different facets of an interview(assuming anyone actually cares about who they are hiring).  Sure you wanna know if they are professional and passionate about technology, that makes sense.  How do you find out if someone is professional? You'll find out during the interview, do they trash past employers or employees? Note: Trashing previous employers and/or employees is perfectly acceptable, just not in the interview :) Are you passionate about technology? Too easy to answer yes to, so interviewers have to plan some questions that cause candidates to give up examples of how they are passionate.  But is that all? Nope.

The Job Description and Hands On Test

Let's say you're hiring a software developer with at least 3 years experience developing websites using ASP.NET, C#, and Sql Server(or any other database for that matter).  A laptop would be required for the interview, something I'd bring for the candidate(or a desktop, whatever is easiest).  And since I'm into the virtual image kick, I'd have one created already for the candidate, complete with visual studio 200x and Sql Server 200x, and firefox set as the default browser;i'd actually hide all of the ie shortcuts too :)

Requirements

I would have some requirements typed up, preferrably written by a business analyst or someone who's not a software developer.  And I would make some of the requirements vague(so they have to ask questions in order to complete the task).  I'd hand the requirements over to the candidate with the instructions, "fulfill the requirements, no visual designers are allowed in either of visual studio or sql management studio".(details like connection strings would be included).  At that point the interviewers would sit back and watch the show.

Watching the Show

Watch what?  Well did they clarify the requirements, remember, they're written too vague to be able to actually complete correctly, so questions are expected. 

How do they type? I'm convinced that if you're clumsy on the keyboard, or if you're poking around visual studio menus for the "Build" menuitem, you lied on your resume about having ANY experience with visual studio.  I would expect that for someone who types, and is not used to the provided equipment, would type fast and make a lot of fat finger mistakes, which is fine.

The database part would interest me the most.  How many people put "Sql Server Expert" on their resume, and can't issue a CREATE TABLE command in a query window(and yes, it has to actually create a table)?  OK.  Don't know the command? that's no problem, but i wanna see how or if the candidate can find the answer.  This also downgrades their status of "Sql Server Expert" to "i've connected my .NET app to MS Sql Server and that's about it". 

The task would be simple enough to complete within say an hour, actually maybe even 30 minutes.  I'd love to see if they're smart and pick up some tool of their choice(Subsonic, LLBLGEN trial version, their own CodeSmith templates, whatever) to help them complete the task on time; or is most of the time spent writing sql.  The data access code would drill their knowledge of System.Data as well.  Did they write something like "select * from blah where somefield = '" + somevar + "'"? or did they write "select * from blah where somefield=@somefield"(note the use of the parameter).  Lack of parameter use is a pet peeve of mine.

Lack of a designer is good too.  If you're really passionate about what you do, you'll know, maybe not prefer, but you'll know how to type html into the text editor.

Other Questions

What your favorite unit testing framework? How many computers do you have at home and what are they? What OS? What hardware?  Who's blogs do you subscribe to?  What was the last project your were proud of? What made you proud of it? Do you own an IPhone? MP3 player? Any other geeky gadgets? What would you do if you met the Prince of Darkness? Have you ever been to the Rio? What's your favorite beer? Which is better, Blade or Roadhouse? (It's a trick question, they are both awesome).  Who's better, Killswitch Engage or Motley Crue? (again, another trick question; and yes I am going to the Cruefest next month) How many times have you watched Old School? How bout Office Space?

For those who know me, you might be thinking, but all of those questions reflect things specific to me, they're not general questions, but they're things that _I_ look for, and that, my friends, is the point.  Questions like that have to, at some point, come from those the candidate would be working with as part of the interview process.  Can the candidate get along with the people already working there? Candidates interviewed by recruiters or anyone else they won't be working with are ultimately going to suck.

Questions I Don't Care About

I could only think of one off the top of my head: Can you draw a UML diagram? If you can, sweet, teach me the next time I'm finding it difficult to fall asleep, I don't how to do that, and I don't plan on learning.  UML == BORING.

Cool Tool:ColorZilla For Firefox 3.0

Posted on June 17, 2008      0 Comment(s)

Yay! The ColorZilla plugin was recently updated to work with the latest release of Firefox, good for color picking.

How Expensive Is Reflection?

Posted on June 10, 2008      0 Comment(s)

I've seen many blog posts recently that give guidance on late binding with reflection versus early binding with casting.  What seems to always be missing is any data supporting the claims.  How can you tell me something is better without showing me how you know this? Here's my sooper scientific(read, not scientific) performance test to help demonstrate how much faster early binding can be over late binding using reflection. I ran each routine through 100 iterations, 1000, 10000, and 100000 iterations.

Late Bound Test Code

OK. The main point I wanted to test was the cost of getting a value from a property on an instance of "something" through reflection. This means calling type.GetProperty("SomeProperty").GetValue(instance, null). So here's the late bound code:

private void LateBinding(IList orders, int iterations)
{
	for (int i = 0; i < iterations; i++)
	{
		foreach (object item in orders)
		{
			Type type = orders[0].GetType();
			StringBuilder html = new StringBuilder();
			html.AppendFormat("<td>{0}</td>", type.GetProperty("ID").GetValue(item, null).ToString());
			html.AppendFormat("<td>{0}</td>", type.GetProperty("Date").GetValue(item, null).ToString());
			html.AppendFormat("<td>{0}</td>", type.GetProperty("Amount").GetValue(item, null).ToString());
			html.AppendFormat("<td>{0}</td>", type.GetProperty("SalesRepName").GetValue(item, null).ToString());
		}
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Early Bound Test

Basically this is using a generic List of type Order and the properties are accessed right off of each instance.

private void EarlyBinding(List<Order> orders, int iterations)
{
	for (int i = 0; i < iterations; i++)
	{
		foreach (Order item in orders)
		{
			StringBuilder html = new StringBuilder();
			html.AppendFormat("<td>{0}</td>", item.ID);
			html.AppendFormat("<td>{0}</td>", item.Date);
			html.AppendFormat("<td>{0}</td>", item.Amount);
			html.AppendFormat("<td>{0}</td>", item.SalesRepName);
		}
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14

Results or Whatever

There's actually quite a big difference, bigger than I thought before the sooper scientific test. Under 1000 iterations it's hard visibly see a difference, but over the 10,000 mark there is a major difference.

Here's my wicked cool test code in all it's glory.

15 Minutes

Posted on June 9, 2008      2 Comment(s)

Pop Quiz Hot Shot: How long does it take you to write CodeDom code, compile it, and call it? Do you even know where to start?  This is what  I came up with in 15 minutes, started at 10:17pm ended at 10:32pm:

using System;
using NUnit.Framework;
using System.Reflection;
using System.CodeDom;
using Microsoft.CSharp;
using System.CodeDom.Compiler;

namespace DataBoundControls
{
	[TestFixture]
	public class CodeGenTests
	{
		[Test]
		public void PopQuiz()
		{
			CodeTypeDeclaration clazz = new CodeTypeDeclaration("TableGenerator");
			CodeMemberMethod method = new CodeMemberMethod();
			method.ReturnType = new CodeTypeReference(typeof(string));
			method.Parameters.Add(new CodeParameterDeclarationExpression(typeof(string), "name"));
			method.Name = "SayHello";
			method.Attributes = MemberAttributes.Public | MemberAttributes.Final;
			method.Statements.Add(
				new CodeMethodReturnStatement(
					new CodeArgumentReferenceExpression("name")));
			clazz.Members.Add(method);
			CodeNamespace nspace = new CodeNamespace("Dummy");
			nspace.Types.Add(clazz);
			nspace.Imports.Add(new CodeNamespaceImport("System"));

			CodeDomProvider generator = new CSharpCodeProvider();
			//Next line shows what was generated
			//generator.GenerateCodeFromNamespace(nspace, Console.Out, new CodeGeneratorOptions());
			CodeCompileUnit unit = new CodeCompileUnit();
			unit.Namespaces.Add(nspace);
			CompilerParameters parameters = new CompilerParameters { GenerateInMemory = true };
			CompilerResults results = generator.CompileAssemblyFromDom(parameters, unit);
			Assembly ass = results.CompiledAssembly;
			Type type = ass.GetType("Dummy.TableGenerator");
			object inst = Activator.CreateInstance(type);
			MethodInfo sayhello = type.GetMethod("SayHello");
			string result = sayhello.Invoke(inst, new object[] { "Chris" }).ToString();
			Console.WriteLine(result);

		}
	}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46

 

How to Make Things Complicated

Posted on June 7, 2008      0 Comment(s)

I have some classes that work together to make writing html easier.  One class is Element and one Attribute that represent their obvious pieces of html.  One feature implemented is the ability to add attributes as a string like this: border=0;height=100%; .  As a feature, that string is parsed into two attributes, one representing border with a value of 0 and the other representing height with a value of 100%.  Simple, right? Totally. 

Here's the code i was using to parse that string into attributes, the first thing is to split on the semi-colons:

public virtual Element AddAttribute(string nameValuePairsSeparatedByAnEqualsSign)
{
	string[] nameValuePairs = nameValuePairsSeparatedByAnEqualsSign.Split(';');
	foreach (string nameValuePair in nameValuePairs)
	{

		if (String.IsNullOrEmpty(nameValuePair))
			continue;

		this.AddAttribute(new Attribute(nameValuePair));
	}
	return this;
}
1
2
3
4
5
6
7
8
9
10
11
12
13

 And here's the contstructor for an Attribute:

public Attribute(string nameValuePairsSeparatedByAnEqualsSign)
{
	if (String.IsNullOrEmpty(nameValuePairsSeparatedByAnEqualsSign))
		throw new ArgumentException("nameValuePairSeparatedByEqualsSign is null or empty.", "nameValuePairsSeparatedByAnEqualsSign");

	string[] nameValues = nameValuePairsSeparatedByAnEqualsSign.Split('=');
	_name = nameValues[0];
	if (nameValues.Length > 1)
		_value = nameValues[1];
}
1
2
3
4
5
6
7
8
9
10

This was all working perfectly until I started a new project, one of the tasks of the project is to create a .csproj file.  One element of a csproj looks like this:

<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
1

That's perfectly legit xml, but that attribute busted my code, the double equals.  So I set out to fix it.  Here's something I came up with that worked, but man, soooooo stoopid complicated:

public static List<Pair<string,string>> Parse1(string attlist)
	{
		List<Pair<string,string>> attributes = new List<Pair<string,string>>();
		List<char> buffer = new List<char>();

		Pair<string,string> attribute = null;
		for (int i = 0; i < attlist.Length; i++)
		{
			char c = attlist[i];

			if (c == '=')
			{
				if (attlist[i + 1] == '=')
				{
					buffer.Add(c);
					buffer.Add('=');
					i++;
				}
				else
				{
					if (attribute == null)
					{
						attribute = new Pair<string,string>();
						attribute.First = new String(buffer.ToArray());
					}
					else
					{
						attribute.Second = new String(buffer.ToArray());
						attributes.Add(attribute);
						attribute = null;
					}
					buffer.Clear();
				}
			}
			else if (c == ';')
			{
				attribute.Second = new String(buffer.ToArray());
				attributes.Add(attribute);
				attribute = null;
				buffer.Clear();
			}
			else
				buffer.Add(c);
		}
		if (attribute != null)
		{
			attribute.Second = new String(buffer.ToArray());
			attributes.Add(attribute);
		}
		return attributes;
	}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51

I asked Levon Hackmeister how he'd do the same thing, and had a wicked simple solution, replace the double equals with something else like deq, do the original split on equals, then replace deq with the original ==.  Blam, done.  Here's the modified code, just needed to change the constructor on Attribute. Note the Replace("==", "&deq;") before the split on equals, and the Replace("&deq;", "==") when assigning the value.

public Attribute(string nameValuePairsSeparatedByAnEqualsSign)
{
	if (String.IsNullOrEmpty(nameValuePairsSeparatedByAnEqualsSign))
		throw new ArgumentException("nameValuePairSeparatedByEqualsSign is null or empty.", "nameValuePairsSeparatedByAnEqualsSign");

	string[] nameValues = nameValuePairsSeparatedByAnEqualsSign.Replace("==", "&deq;").Split('=');
	_name = nameValues[0];
	if (nameValues.Length > 1)
		_value = nameValues[1].Replace("&deq;", "==");
}
1
2
3
4
5
6
7
8
9
10

Sometimes it's easy to skip over an easy solution and jump right into a pile of crap. 

Regular Expressions

I thought about using regex. That's as far as I got though :)

Why I Require Email When Posting Comments On My Blog

Posted on June 7, 2008      0 Comment(s)

2 reasons, one of them is not necessary, and is merely for commenter bling, the other helps me by eliminating 99.999 percent of spam comments.

Avatar

Wikipedia describes an avatar as ...a computer user's representation of himself or herself.... Here's my avatar, those who know me will see the obvious resemblance(note the glistening pecs):

When I post comment on a site that knows how to grab an avatar by email, my avatar appears next to my comment. 

Email Spam

Comment spam sucks.  When I was using just a CAPTCHA image, i was getting thousands of spam comments a day, totally sucked.  Except for a few randoms, and by "a few" i'm talking like less than 20, akismet has filtered all of the spam.  It's free for personal use like this blog, all you have to do is sign up for a wordpress blog. Once you get that set up you get a api key sent to you and you're set to go.  Go where? Exactly.  I used the Akismet Api from codeplex to use the akismet service, super simple.  Right before a comment gets to me it's filtered through akismet, if it gets a thumbs down from akismet as being legitimate, the comment is ignored and not passed on to me for moderation.

"Make everything as simple as possible, but not simpler."

Posted on June 4, 2008      3 Comment(s)

Try Catch blocks are tricky bitches.

I've ranted about them before.

Do not abuse them.  How do you abuse them you ask? You use them to catch only System.Exception, anywhere in your code without thought.  And then do nothing with the exception.  Why do nothing? Because you caught System.Exception which is completely fucking useless in determining what went wrong! There I said it.  Sorry mom, this deserved an F-Bomb...

I found this article via DotNetKicks the other day.  It describes some best practices in handling .NET exceptions.  When I read the article it was a little annoying, but not quite enough to make me respond.  But now after reading another DotNetKicks referral on try..catching(I'll hit that one later in this post), here it goes.  There's a link to the MSDN best practices dealio on handling exceptionsBravo.  More people should read those docs, judging from code I've seen, very few .NET developers have seen the design guidlelines.(if you're reading this and you're one of those developers who hasn't been there, GO THERE NOW!).

My beef with the article is the suggestion of throwing an exception that contains all of the details of what an end user could possibly do, due to this new exception.  Here's the meat to my beef(I couldn't resist).  An exception should be used for exceptional sitiuations.  These situations are ones that you as a programmer have no control over and cannot necessarily test for or predict, hence an exception would occur.  If I can't connect to a database because the network went down, I'll get a SqlException with a message and other information indicating so.  Without creating a "wrapper exception", some global exception handler in your application can catch that and determine "oh, there's a SqlException, indicating we can't see the database anymore, let's see, what can the user do....oh ya, NOTHING."  And display any one of a million great error pages like these great 404 error pages highlighted on the bomb ass smashingmagazine.com site.

Don't get me wrong, the author lists 4 things for better exception handling, my prob is with #3, the others are spot on.  There's no way as the developer of some classes that will be used by someone else, to know what the user's options are, since you won't know who the user's are to begin with.  There's no course of action, nothing.  Something broke, let it bubble as close to the user as possible but not all the way, at the last possible moment, intercept and handle appropriately, don't waste time binding volatile information like support details to custom exceptions in your code.

Albert Einstein

The title of this post is a quote from Albert Einstein.  This post was actually inspired by this article on try-catching in a single line of code.  I realize the code example was strictly just an example, but I can't help but be annoyed by the returning of values just as worthless as an HRESULT.(oh ya, don't miss the COM days at all!)

So back to the code. Taken for what it is, an extension method that can be used to catch exceptions, yay, cool example.  However, if I ever saw that in someone's code I had to maintain I think I'd explode.  It doesn't make sense.  You're taking a step backwards with delivering error codes in place of the exceptions.  That's crazy.  Why wouldn't you want that exception to bubble up? I guess it might depend on the app, but c'mon, return codes in place of SEH(Structured Error Handling) that everyone whined about needing in the COM days?(and yes i realize you don't have to return an error code, but you're still doing "something" inside of a masked catch block that can be handled in a better place, closer to the application level).

Some Thoughts on Exception Handling(and Throwing)

One of the commenters(Will) of this article said it best ..."handle your exceptions at the last possible moment within the current context." For applications, that usually means the UI layer... and that is absolutely the truth.

My rule of thumb(more of a guideline not set in stone) on throwing exceptions is at the method level.  If a method cannot succeed without proper inputs, an appropriate exception should be thrown indicating that fact.  This forces the input checking all the way back to the end user if need be.  If my code on the backend requires that the user typed in an integer for whatever, i'll be checking on the backend for an int and throwing an exception(either i or some piece of .NET will throw that exception) and the end user will be faced with a yellow screen of death.  What does that mean? if the user must put an int into a field, then make sure whatever the UI is, winform, webapp, whatever, checks at that level to make sure the user entered that information appropriately.  It's VERY easy to do. You just have to do it...

Railgun Madness

Posted on June 3, 2008      0 Comment(s)

Pete reminded me about how I used deliver beating after beating in Quake II.  So I found my Quake II disk(yep, same one from Rates Dot Bomb) and loaded it up in the virtual.  The mouse is completely screwed up, but using the keyboard works like a champ.  The video capture is choppy only because I'm recording the full screen, when not capturing the screen, the game plays as good as could be.  Check it out:

http://panteravb.com/codecasts/quakeii-virtual3.html

I figured out how to capture the sound, so if you got speakers, turn em up.

May Sucked

Posted on June 3, 2008      1 Comment(s)

I didn't get a lot of things accomplished in May.  Work sucked too.  So in the spirit of trying to have some fun I got Quake III Arena up and running on a virtual machine running XP.  The XP VM has 2 gigs of ram dedicated to it, plus I bumped up the vram to 128 megs.  The host machine is running 32 bit Windows 2003 Server with 8 gigs of ram. The sound was horrible, and the video was choppy, but I could almost play it well just using the keyboard.

Here's to a better June: http://panteravb.com/codecasts/quakeiii-virtual.html.

ps. I originally had recorded about a minute and 17 seconds worth of footage, but the rendered Flash file was 100 megs and would have taken years to upload, so I cut it up into a 10 second slice(still 7 megs!).