Dude, write a book

Cowboyd. Future Famous Author:

“So you’re going to give this jacket to me.”

“Yes yes. I gift. To you.”

“What do you want?” I said.

“Want? I want to give you a litle gift.”

“What do you want?” I repeated.

He did not respond at once, instead readying his proposal since it was obvious that was all I was waiting for. Then he said slowly “I give you a little geeft, you give me a little geeft.”

Finally. Christ it took this guy long enough to admit that it was at least some sort of transaction he was proposing. In retrospect I wonder if he was covering his ass in case I turned out to be part of the ultra-elite squad of undercover cops that hangs around in parking lots –Hatchling to nest. Hatchling to nest. Operation “check email and then fart around in the parking lot” was a raging success.

Javascript: its actually pretty cool

So, I used to think that javascript was evil and bad, and made for brittle websites that only worked in one browser. That danger is still present, but its not really the fault of javascript. Sticking to the ECMA and W3C DOM standards should avoid most of the pitfalls.

I’m more interested in Javascript as a language. Its a prototype-based OO language. Prototype based languages don’t have the concept of classes per se, you define types by instantiating objects and then attaching function definitions. Once your prototype object has all the behaviour you want, you can use it as a template to instantiate other objects of the same type. Functions can be defined either as global, or bolted to an object as methods. Functions can also be directly referenced as variables. Function parameters can either be named explicitly, or referenced by indexing into the arguments array. So although a function may state that it takes 2 arguments by saying ‘function foo(bar, baz)’, there’s nothing to stop you calling it with 20 arguments.

What is also very cool is that you can make HTTP requests directly in javascript, and refresh parts of the page independently. This makes it possible to build very interactive portal applications that can update the screen asynchronously without an obvious browser refresh.

The netWindows open source project has a bunch of very useful stuff, including a standalone signals & slots implementation for javascript, which is very handy for building event-driven pages.

Avi Bryant has graciously published some javascript that can selectively replace chunks of HTML based on an asynchronous server call.

The Oddpost guys even built a full fledged 3-pane email application (with drag and drop) inside a web browser. Shame they’re no longer taking subscriptions. I want one!

Peelable UI’s

On pretty much every project, the subject of whether its feasible to perform unit testing (and indeed, TDD) at or near the user interface comes up. Over the last couple of projects the design that I find easiest to work has looked something like this:

public class SimpleView : ISimpleView {

private TextBox txtFirstname;
private Label message;
private Button okButton;

public string Firstname {
get { return txtFirstname.Text; }
set { txtFirstname.Text = value; }
public string Message {
set { message.Text = value; }

private void okButton_Clicked(object sender, EventArgs e)

public interface ISimpleView {
string Firstname { get; set; }
string Message { set; }

public class SimpleController {
private ISimpleView view;
public SimpleController(ISimpleView view) {
this.view = view;
public void OkClicked() {
string greeting = "Hello, " + view.Firstname + "!";
view.Message = greeting;

The general pattern is that any operation that requires the system to take action should be a method call to the controller, and that all the values from the view should be exposed on the interface. Widgets should not leak from the view into the controller. This approach allows for testing with NMock or JMock, as well as keeping the view classes so thin and logic-free that it is a simple task to peel off and replace with an alternative implementation (swapping thick client for web front end for example), or a test harness.