Repeatedly polling server with ajax

I’ve made a small fiddle that illustrates repeatedly polling a server asynchronously once every second with the ability to pause and resume for posterity. For more advanced functionality, including long-polling then SignalR is your man, but for something simple this does the job. The code is also reproduced here:

Null reference exceptions considered harmful

Making a call to a service and getting a null result usually throws me, and when it throws me it usually means my code is about to throw an exception. This case applies especially to null instances of collection types. Why would you want to return null for a collection? I can’t think of a […]

Testing asynchronous JavaScript

By making AJAX calls directly to the server from your JavaScript view-model it can be impossible to get the code under test. A simple solution is to fake the calls and make them synchronous. This example view-model for a library takes a function that will make a call to the server to check out a book […]

Implicit casts for modifying legacy code

When dealing with legacy code it can be difficult to see where to make a change. Seeing and tracking the usage of a method /constructor parameter can require a skilled eye. It is sometimes easier (if possible) to change the value of parameters by changing their types instead to one which provides an implicit cast […]

The trouble with shims

Shims are described in Michael Feather’s book on legacy code as a stepping stone on the path to dependency inversion – they are a technique for breaking apart untestable code. Visual Studio 2012 ships with some libraries that are able to magically intercept and manipulate calls to code that are normally untouchable – even .NET […]