How do you interview a programmer?

3 Comments | Jun 12, 2011

How do you know the programmer you are interviewing is the best of the bunch?

I'm talking about natural programming talent. The best programmers will pick up new technologies fast and be using them in an innovative, imaginative and logical way. They will write clean logical code that rarely fails and is easy, even pleasing, to follow.

Most interview tests can be passed by reading a textbook and having a little experience. They don't weed out the truly good programmers from the ones who learn programming parrot fashion.

For me, an interviewer needs to test the interviewees problem understanding and solving techniques as this underpins any good programmer. I think a good way of doing this is via logic games.

Blocked Car/Parking Lot

The user has to move other cars out of the way to get the yellow car out of the parking lot. This exercises the programming problem solving muscle. The user has to think about many factors as the levels get harder (e.g. I need to move the red car, but to do that I have to move the blue car, but I cant because....)

Here is an example - http://www.funatico.com/flash-games/yellow-out-2042.html

River Crossing Puzzle

A classic logic puzzle. The user has to get a group of people from one side of a river to the other, but the boat cant take them all at once. There are several rules restricting who the people are happy to be with that restrict the order they can be moved. This is the sort of problem common when programming. The core task is simple, but restrictions in the environment or business rules add complications.

Here is an example - http://www.smart-kit.com/s888/river-crossing-puzzle-hard

 

I'm not suggesting this is the only test you should try, or even the best, but it at least tests something that is nearly always missed.

Compact Framework Visual Inheritance P/Invoke Designer Error

2 Comments | May 06, 2011

This is a problem I've struggled and struggled with. No workaround or fix I found on the internet worked. In fact the work around I finally got to work incorporates a combination of fixes.

Symptoms

The Form or User Control designer in Visual Studio displays the following error:

Visual inheritance is currently disabled because the base class references a device-specific component or contains P/Invoke

Cause

In case you didn't know P/Invoke is used to access un-managed code (com components). The designer has to compile and initialise your forms via the constructor to display them on the design pane, however, it is unable access un-managed code. If your forms inherit from a custom base form and the designer sees a P/Invoke anywhere in your code (even if it will never access it) it throws the above error.

Two examples of this I've found are:

  • The InputPanel Control
  • The Sqlite .Net Libraries from PHX Software

See here for more - http://msdn.microsoft.com/en-us/library/ms228851.aspx

Solution

As hinted at before there are two parts to the solution. First you need to tell the designer “Don't worry about it, I wont let you touch P/Invoke code”, then you need to live up to your promise.

Part 1

Mark your base form with DesktopCompatible(true) to calm the designer.

  1. In Solution Explorer, right click your form and select "View Class Diagram".
  2. Select the class blob.
  3. In Properties Pane click "..." button in the "Custom Attributes"
  4. Paste DesktopCompatible(true) into the text area and click ok.

Part 2

Avoid code that references the P/Invoke code. There are many ways to do this but here is my simple method.

The designer pane only initialises the forms it requires. When the program runs for real, the static class Program opens the first form and your code takes it from there. That little nugget of information makes my method work.

  1. Create a static class with a static property as such
    public static bool IsRuntime { get; set; }
  2. In the Main function in the Program Class (Program.cs) set the above property to true before it opens the first form. This code is only run at runtime.
  3. Use this property in if statements in your code to avoid P/Invoke calls when IsRuntime is false.

SQLite Solution

The above solution would work if you are using SQLite, but you would end up with very messy code as you are probably referencing your SQLite libraries quite often. This is a neater solution that keeps all the runtime checks in a central place.

Part 1

Same as above.

Part 2

Create a class that sets up your SQLite Objects and perform your checks there. Unfortunately I cant publish my class here as the source code belongs to my client, however, I can give you a few snippets to give you the general idea.

1. Create an IsRuntime Property

2. Get the calling code (e.g. Form) to pass in the IsRuntime flag

3. Use Interfaces to avoid any declaration of SQLite classes and only initialise SQLite classes when IsRuntime is true.

Connecting an MVC project to an SQL database

3 Comments | Mar 29, 2011

I'm just getting to grips with MVC linq etc etc and came across what looks like a common stumbling block. For the more experienced of you reading this please refrain from shouting "Dumbass" at me.

All the tutorials are either Code First examples or they create the database from scratch in the App_Data directory. All well and good for a tutorial that need to be easily portable to the readers computer, but not very helpful when setting up a full scale MVC application.

My first problem was my lack of knowledge of Linq to SQL. If you fall into this category have a look at this link - it's gold dust.

http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx

Finally, how to add an external SQL database to your MVC project:

  1. Right click on "Models" folder, select "Add New Item"
  2. Add a "Link to SQL Classes" item
  3. Open your "Server Explorer" pane (if you cant see it try "View" on the menu bar and "Server Explorer"
  4. Right click on "Data Connections" and select "Add Connection"
  5. Follow the instructions.
  6. Almost there....
  7. Expand your newly added database to view the tables.
  8. Drag the tables you want over to the main pane of the "Link to SQL Classes" item you added at the start.
  9. Hey presto, you have a database context you can run Linq queries against.

Please bear in mind you will need to use the "Models" namespace to reference you database context objects.

....

And now back to highly sophisticated programming!