A safe language on a safe OS

Oliver Brown
— This upcoming video may not be available to view yet.

Have you heard of “managed” code? Generally it refers to code that has no direct access to memory and instead has to access everything through a protected interface of sorts. The main advantages are that a program can’t go poking memory that it shouldn’t and useful rules can be enforced like type safety.

The most prevalent example of managed code is nearly everything running under .NET/Mono. Admittedly you can mark parts as “unsafe” letting you use pointers and stopping the garbage collector arbitrarily moving your data around but most of the usefulness comes from avoiding this where possible.

The problem is, you can’t always avoid it. The main reason for this is you have to access existing non managed systems. Rewriting everything in managed code is not feasible and although you can lessen any problems by writing wrappers so there is only one point of contact between managed and unmanaged code, problems can still occur - the sort of problems the managed code was supposed to prevent.

Microsoft are investigating a solution. After reading that last paragraph, the form of the solution should be obvious but for the most part it’s unworkable in the real world - eliminate all unmanaged code.

A lot of people claim managed code, or specifically .NET is slow and inefficient. Well it is. But it can be made faster. Most inefficiency is caused by a lot of run time checks to make sure everything is as it should be. If the code lives in an entirely managed world however most of these checks can be removed since (barring random hardware failure) the program can be guaranteed to satisfy the run time checks at compile time.

For more details about Singularity, Microsoft’s research operating system written in C#, check out this article by James Larus, Galen Hunt, and David Tarditi over at MSDN.

Multiple forms in ASP.NET

Oliver Brown
— This upcoming video may not be available to view yet.

I previously ranted that being unable to have two ASP controlled forms in a single ASP.NET page is a serious flaw. They may be a way round it though. I would assume that ASP.NET can’t output two “smart” forms (the ones with runat="server") on the same page but I’m pretty sure that there is nothing stopping a HTML page itself actually holding two of them. Of course that could be wrong.

Essentially all you have to do is load the extra forms using AJAX and I think everything will work.

(I’m working a on a page (not in ASP.NET) that has a table of data with a status column. Each column needed to have a drop down box letting you change the status. Since the number of statuses is large I decided to have a link that AJAXly changed into the dropdown box and a button when you clicked it. Of course you could click all the links and not submit any of the forms leaving you with a page that actually has a bout 30 forms on it.)

No computer - no internet

Oliver Brown
— This upcoming video may not be available to view yet.

Not having a computer also means that I don’t have internet access outside of work.

I say this just to make it look like I’m still updating the blog.

Explaining the Matrix

Oliver Brown
— This upcoming video may not be available to view yet.

The Matrix was quite a good series of films. But without any extra interpretation left most viewers reasonably underwhelmed.

Well see what you think of this theory.

It’s specifically about the second movie, The Matrix Reloaded (there is a link to one about Revolutions too) but I think the second is where the most understanding is required.

It also has a prediction about what could happen in the third movie (it was written before it was released) and I think I like it more…

Money for Picasa

Oliver Brown
— This upcoming video may not be available to view yet.

Google are now offering $1 for anyone you get to install Picasa (their clever photo organisation software thing) as part of their AdSense referral program.

So first, go install Picasa and then come back and go join AdSense so you can benefit yourself. And if you haven’t already, get Firefox: You can get AdWords if you want but I doubt you’ll spend enough to get me anything.

BackBase really pushing AJAX

Oliver Brown
— This upcoming video may not be available to view yet.

BackBase is another AJAX toolkit. This one is different though. It’s not really an AJAX toolkit, more a toolkit powered by JavaScript taking advantage of AJAX.

The clue is the price. Yes it has a price - $2000 to be exact. There is a “community edition” that is free for personal use though. Anyway, I don’t have time to run down all the features but basically it defines a whole new bunch of tags allowing you to create complicated content in a declarative HTML style way. These tags are then translated into proper XHTML on the fly by the back end JavaScript engine. Since the clever work is actually handled by the browser, you’re free to use whatever you like on the server (PHP, Ruby) including static HTML pages - outputting BXML is no different to outputting HTML. In fact BXML has a very ASP.NET feel to it and embedding BXML into an XHTML page along with ASP content could have the ultimate cleanness about it (syntax isn’t one of my complaints about ASP.NET).

It should be noted that Microsoft are working on Atlas which could be something very similar but I haven’t looked into it… It all seems very clever.

Computer not here…

Oliver Brown
— This upcoming video may not be available to view yet.

My new computer has still yet to arrive. I was expecting to be able to write a hands on review of MCE by now.

Silly things with JavaScript closures

Oliver Brown
— This upcoming video may not be available to view yet.

From a theoretical programming point of view, JavaScript is immensely cool. You can do some amazing things with it. Although I’m not entirely sure whether you should.

For example I had a bunch of elements on a page I needed to update using AJAX. I needed a function I could pass the URLs and ids of elements to replace with those URLs and then have it perform each replacement in turn (I’ve seen IE have problems with simultaneous AJAX requests).

First I replace a simple replace_id function that accepts three arguments. An element id, a URL to GET to replace its contents with and finally a function to be called when it’s all completed.

And then things got silly.

function chain_replace(urls, ids) {
    id = 0;
    next_id = function() {
        if (id < = ids.length) {
            return function() {
                replace_id(urls[id], ids[id++], next_id());
            }
        }
    };
    next_id()();
}

Now the next_id()(); bit towards the end should be a clue that something a little odd is going on. But I must confirm that this code does actually work. With enough arguments it might make the browser explode with some sort of call stack problem though…

Coop gaming

Oliver Brown
— This upcoming video may not be available to view yet.

Finally someone in the mainstream agrees with me.

There is a section in PC Format magazine that says cooperative play in upcoming games will be a bigger part. Coop gaming, especially in first person shooters is tremendously fun. I spent a lot of time playing Duke Nukem 3D and Doom coop on my PlayStation. Very few games after that supported coop modes (although I realise that it brings some complicated design issues).