Python Programming, news on the Voidspace Python Projects and all things techie.

Silverlight: Python in the Browser

emoticon:clock Ok, so after a couple of days digesting it, the new Microsoft announcement is really big news. Everyone is talking about it, well, everyone except the Python community [1]. Smile

There are two important aspects, and Microsoft chose to announce them at the same time.

  1. IronPython 2.0 is built on top of a new layer called the 'DLR', the Dynamic Language Runtime. This abstracts a lot of the useful elements from IronPython 1.0 into a dynamic type system and hosting environment for dynamic languages. The DLR is Open Source, and on top of it Microsoft are developing four languages:

    • IronPython
    • IronRuby
    • A dynamic version of VB
    • Javascript

    The DLR is shipped with the IronPython 2.0 distribution. IronRuby is not yet available [2], but an alpha ought to be available this week. It doesn't yet run Rails, but it will eventually. Through the DLR, dynamic languages should be able to share libraries and use each other's objects...

  2. SilverLight 1.1 ships with a customized version of the CLR: the .NET 'Common Language Runtime'. This only contains trusted assemblies, so applications running in it are sandboxed. The exciting part, is that the DLR runs on top of it! So you can now do rich client programming for web-apps, with full access to the browser DOM (plus the Silverlight capabilities) using IronPython or IronRuby. This is big news [3]. You also have the .NET libraries, including WPF/E which is the browser side equivalent of Microsoft's new user interface library. Microsoft are touting the media-streaming capabilities of Silverlight and I have no idea what other goodies are lurking inside it for building applications, yet...

Silverlight is cross-platform and cross-browser, well partly anyway [4]. Smile

The bad news is that the DLR doesn't yet compile and run on Mono. This should just be a case of fixing compiler bugs, and possibly implementing a few more classes and methods. Seo Sanghyeon has already made some progress on this, and based on past experience it won't take him very long.

Additionally, there is no Silverlight client for Linux. However, Miguel de Icaza, the project lead for Mono, is very excited about implementing the Silverlight CLR; much more excited than he is about implementing WPF for the desktop which he thinks will see very slow developer uptake.

So what can you do with Silverlight? Well, up to now I've only got as far as running the demos. You'll need Silverlight 1.1 Alpha installed and the Silverlight 1.1 SDK for the first set of demos.

If you want to try it with Firefox you'll also need an HTTP server (I use CGIHTTPServerWithSSI which works fine, just drop it into the samples directory). I've had some of the demos working on Windows. Andrzej Krzywda tried it with Firefox on the Mac and Firefox kept crashing...


The getting started pages will recommend Visual Studio upgrades etc, but you don't need any of that rubbish. Wink

You must restart Firefox after installing Silverlight.

Some of the files in the sample folders have names like default.html.js, which causes AVG (anti-virus) to bring up the 'hidden extension' warning, very annoying.

The SDK documentation seems to partly come as an ASP site which you are expected to setup. Yeeurgh! Luckily the other samples are very easy to use.

From the SDK, the only demos I could get working were the 'DLR Console' and the Image Viewer [5]. The DLR Console is particularly impressive; it gives you a Python / Javascript console in the browser. You have a live WPF canvas, autocomplete in the console and can switch between Javascript and Python (with access to the same objects). Pretty cool.

The DLR Console in the Browser

The way images appear in the image viewer demo is very slick.

As well as the samples that come with the SDK, there are some more samples of using IronPython with Silverlight available on Codeplex:

These are a collection of Javascript and IronPython samples that run on the DLR, and they look like a good place to start exploring.

The Clock Demo The DLR Console in the Browser Wordfinder Game Word Tiling Animation

As an illustration, here is the resetboard function from the Wordfind sample:

def resetBoard():
    # clear the previous tiles

    # reset to the top-level tree if we already had a word.
    global CURTREE

    # generate the letters & setup the board
    global TILES, PRESSED

    letters = generate_letter_board(WIDTH, HEIGHT, 0)

    rows = []
    for y in xrange(HEIGHT):
        curRow = []
        for x in xrange(WIDTH):
            letter = letters[y][x]
            tile = addTile(x*10 + y, letter, int(RAND.random()*8)+1, y*50 + 50, x*50 + 50)
            curRow.append((tile, letter))
    PRESSED = []
    TILES = rows

    # grab controls we'll interact w/
    PROGRESS = Browser.HtmlPage.Document.GetElementByID("progress")
    STATUS = Browser.HtmlPage.Document.GetElementByID("status")

    # find all words
    WORDS = find_all_words(letters)
    FOUND_WORDS = []

You can see that the browser DOM is accessed with calls like Browser.HtmlPage.Document.GetElementByID("status"); nice and amenable to experimentation. If you ignore the demeter violation, it could almost be called Pythonic. Wink


One use of this that immediately springs to mind is for creating online interactive Python tutorials: using a sandboxed Python interpreter that runs on the client...

Personally I find the idea of being able to write rich client-side web applications with Python very exciting, but the responses from other developers I've talked to have been much more lukewarm. Comments include, 'it sounds like Java applets from 1995', 'I don't like Microsoft tools', 'it means installing another runtime', 'I like Javascript' and so on... Other commenters cite the lack of development tools for the Mac and Linux. If Silverlight is just an alternative to Flash then I guess this is an issue, but I've never done any flash development. Personally, a Python IDE is the development platform I want - and there are plenty of those.

The worst thing about all of this is that it means I have an extra chapter to write in my book...

[1]Actually that's not true any more, but it was when I started writing this entry, and it makes a good beginning.
[2]John Lam has a screencast showing the console in use with all four languages.
[3]The 'core CLR' that ships with silverlight does run on the Mac, but it is not the same as the full .NET CLR. This means that although IronPython runs on it, you can't use it for running arbitrary IronPython applications, only for those that run in the browser under silverlight.
[4]Currently only IE, Firefox and Safari. No Opera support yet, but their shiny things poster has the Opera logo and says 'soon'. (Konqueror and all the other browsers between them make up 1.6% of my visitors).
[5]The other ones use C# and probably need compiling.

Like this post? Digg it or it.

Posted by Fuzzyman on 2007-05-02 21:14:14 | |

Categories: , ,

Finding Your Way With GPS

emoticon:paper There is a new article by Rene Tse up in the Technology Section.

This article is a review (from real road trips!) of five of the most popular GPS software systems. It lists the pros and cons of the following programs:

  • CoPilot Live 6 from ALK technologies
  • Destinator PN
  • Iguidance 3.0 by iNAV
  • Mapopolis 4.7
  • TomTom Navigator 5

Like this post? Digg it or it.

Posted by Fuzzyman on 2007-05-01 23:52:30 | |


IronPython and the Microsoft Dynamic Language Runtime

emoticon:boxing_gloves Today there is exciting news from the world of Microsoft and IronPython, Jim Hugunin has posted a new blog entry: Smile

This coincides with the first alpha-release of IronPython 2.0 which uses the new runtime.


IronPython 2.0, although in alpha, and currently missing some of the features of IronPython 1.0, targets Python 2.5 instead of 2.4...

When I first skimmed the announcement, my first reaction was 'I know what this means for IronPython - another dependency'. After deeper reading I think this is actually a radical step for dynamic languages on .NET.

This new platform was basically abstracted from the IronPython 1.X implementation, to create a platform designed explicitly for the needs of dynamic languages. Jim's blog continues:

These include a shared dynamic type system, standard hosting model and support to make it easy to generate fast dynamic code. With these additional features it becomes dramatically easier to build high-quality dynamic language implementations on .NET. More importantly, these features enable all of the dynamic languages which use the DLR to freely share code with other dynamic languages...

Several months ago Microsoft hired John Lam [1], the author of RubyCLR. Ruby fanboys hoped that this would accelerate development of RubyCLR, which was languishing in comparison to IronPython. A while ago John declared that he would be announcing something big in April. When the announcement about Silverlight showed up on his blog, the Ruby folk (and many others) were disappointed and wondered how this was relevant to Ruby.

At last the secret is out. On top of the Dynamic Language Runtime Microsoft are building four dynamic languages: IronPython, Javascript, VB and Ruby.

What does this mean? Well John Lam has a few things to say about this - in conversation with John Udell:

it's risky to deploy a standalone language runtime like Perl's, or Python's or Ruby's inside the browser. But the Silverlight languages are nicely sandboxed because they ride atop the dynamic language runtime, and it doesn't rely on any privileged operations.

It's hard to talk about a topic like this without sounding hopelessly geeky. "Look, I've got IronPython using ActiveRecord and LINQ, all inside the Safari browser on my Mac, and I'm debugging it in Visual Studio remotely from my PC."

So the possibility of Python programs directly importing Ruby (and vice-versa) libraries (ActiveRecord or RSpec anyone?) becomes a possibility, or just using Python instead of Javascript as a client-side web-app language. Smile

More importantly for Andrzej, Resolver on Rails is one step closer... Wink

It is hard to find firm news about some aspects of this news on the Microsoft sites. Jim says watch his blog. This blog entry hints about a community release (with an interactive console that can switch between languages !?!?) sometime this week, and there is a page on codeplex for Dynamic Silverlight Samples...

This project is open to the community for submitting samples for Silverlight that are written in dynamic languages implemented on the Dynamic Language Runtime (DLR) for the .NET platform.

There are several Silverlight samples, in both IronPython and Javascript, to download from here.

[1]Currently showing nothing but 'Application Error (Rails)', which is deliciously ironic.

Like this post? Digg it or it.

Posted by Fuzzyman on 2007-04-30 22:28:56 | |

Categories: , ,

Exploring Second Life... with Python

emoticon:cat I've just stumbled upon a German blog entry: IronPython und libsecondlife. Now my German may not be up to much (even less actually), but I think I can understand this:

import clr
import libsecondlife

libsecondlife is an implemented-from-scratch [1] .NET interface to the Second Life API. If you fancy tinkering with it, all you need to do is fire up IronPython.

[1]To circumvent potential licensing issues.

Like this post? Digg it or it.

Posted by Fuzzyman on 2007-04-30 22:02:09 | |

Categories: , ,

Found someone who likes Vista...

emoticon:avocado Vista has had a lot of bad press, and I reckon most readers of my blog will think that this is a thoroughly good thing...

Justin, my web developer friend, has been using Windows Vista Ultimate, and had a surprisingly good time with it:

OEM versions of Vista Ultimate can be bought legally in the UK for around £125. That's not dramatically more than XP cost a year ago. Vista will continue to 'grow by default' from here on.

When I have some more of the book done I'm considering buying a Mac laptop (although I'll probably wait for Leopard). I need Word for writing the book [1], and rather than buy it twice I can use it under Parallels which has incredible integration with Mac OS.

At some point after that, I'll have to make the decision as to which OS to switch my desktop to... (which of 'the three')

[1]Which I don't mind, since I know my way around the basics well enough.

Like this post? Digg it or it.

Posted by Fuzzyman on 2007-04-30 21:17:24 | |


Fun With Python Special Methods

emoticon:contour From a discussion on Python-Dev about possible changes to super. Slightly unexpected results when doing daft things with __call__ and __getattribute__. Smile

>>> class X(object):
    def __call__(self):
            print 'called'
    def __getattribute__(self, name):
            if name == '__call__':
                    return lambda: 'something'
            return object.__getattribute__(self, name)

>>> x = X()
>>> x()
>>> x.__call__()

Like this post? Digg it or it.

Posted by Fuzzyman on 2007-04-29 23:42:35 | |

Categories: ,

Threading in IronPython, Aborting Threads and the Evils of Asynchronous Exceptions

emoticon:cross I've posted a new article in the IronPython section.

It discusses the evils of asynchronous exceptions, looks at the Thread.Abort method on .NET threads, and illustrates simple threading in IronPython.

Like this post? Digg it or it.

Posted by Fuzzyman on 2007-04-28 19:37:32 | |

Categories: , , ,

What makes a test a unit test?

emoticon:dollars Our tests take too long. Some of the unit tests use a live GUI event loop, and these are generally the slow ones. I like this ancient wisdom on unit tests [1] :

The pupil asked the great master programmer Flying Feathers:

"What makes a test a unit test?"

This great master programmer answered:

"If it talks to the database, it is not a unit test.
If it communicates across the network, it is not a unit test.
If it touches the file system, it is not a unit test.
If it can't run at the same time as any other unit tests, it is not a unit test.
If you have to do special things to your environment to run it, it is not a unit test."

Other master programmers, hearing this conversation, jumped in with dissenting opinions and started to argue loudly.

"Sorry I asked", said the pupil, and headed to his bedroom. On his pillow he saw a note from the grand master programmer. The note said:

"The answer from the great master Flying Feathers is an excellent guide. If you follow it most of the time you will do well.

But don't get stuck on any dogma.

Write the test that needs to be written."

The pupil slept well, while the other masters continued to argue long into the night.

[1]'Borrowed', from a post on the eXtreme Programming Mailing List.

Like this post? Digg it or it.

Posted by Fuzzyman on 2007-04-28 19:05:21 | |


PyCon UK and Fun at the London Python Meetup

emoticon:music Wednesday night was another London Python meetup. (The Porterhouse is always crowded; we got good seats in the end, but I think we need a new venue.) I've finished chapter six of 'the book', which is now going out for the very important 'third-of-a-book' review, so I was able to attend guilt free.

As always there was a small but great [1] crowd of people, maybe fifteen of us (?), a really fun time. Sean McGrath [2] was there, fresh from speaking at Publishing 2.0. Regrettably I didn't get him to tell me much about his talk, but I did learn about some of the interesting things he gets up to with XML and Jython (and even IronPython now). I also didn't have time to talk to Simon about mocks (which I'm still keen to learn about), instead he taught me some tricks for using my iPod. Smile

Due to my writing commitments I don't think I'm going to be able to attend Europython this year. (Which is a real shame and I definitely want to be involved next year). That's one of the reasons why I'm so pleased about PyCon UK. Preparations are ramping up and it looks like half of Resolver will be involved in some way or other. I'm submitting a talk proposal on IronPython and Jonathan has put in a brilliant proposal on Test Driven Development. The bosses are also working on the possibility of a talk on Resolver [3]. That will give us a nice hard deadline (albeit later than I would like) for a public beta...

[1]Some really decent folk, living in Northampton these events are about the only time I get to see them though. Sad
[2]A picture of Sean talking about dynamic languages at the recent barcamp Dublin. If the next one is after 'the book' is complete, I will try and attend.
[3]Which has Python right at the heart of it in more ways than one...

Like this post? Digg it or it.

Posted by Fuzzyman on 2007-04-28 15:04:46 | |

Categories: ,

Teaching Kids to Program

emoticon:tooth When I was young I first experimented with programming on a BBC Model B computer, clocked at 4MHz and with a massive 32kb of RAM. I started with BBC BASIC which had an ultra-simple syntax, and I learned to write simple programs with line numbers and GOTOs everywhere. I later turned to the wonderful Amiga, did some assembly language programming, and years later picked programming back up with Python. It all started with the BBC B though, and displaying funky blocks of colour on screen.

Getting started with programming is actually less easier now that computers are more complicated, they don't come with a fun and simple programming language built-in.

There is a great new project to help kids learn to program, with tutorials and a real programming language:

It looks great and has a nice colourful website. The language behind HacketyHack is our old arch-nemesis Ruby. Smile

Python would be a great first language of course, and with its cleaner syntax arguably a better fit than Ruby. Wink

The HacketyHack site hints that other languages might be supported in the future (personally I doubt it though).

Python has (at least) two projects which are good teaching tools:


    Learn to program by moving a robot around (LOGO on steroids?). The website could use some colour, and it is a bit more limited than HacketyHack, but seems to provide a very good introduction to programming.

  • Crunchy

    More a framework for creating tutorials than a teaching tool itself. Lots of potential for teaching with though.

Obviously I would be delighted if someone created an equivalent to HacketyHack for Python. I also hope HacketyHack does well and that through it plenty of kids discover the fun and creativity of programming.

Of course Python's secret weapon for exposing kids to programming, is OLPC [1]. Cool

[1]It's already in the hands of a few Nigerian schoolchildren.

Like this post? Digg it or it.

Posted by Fuzzyman on 2007-04-28 01:12:20 | |

Categories: , ,

All Others Pay Cash: Fun, Ridiculousness and Python

emoticon:speaker Mickey Hadick has finally released All Others Pay Cash onto an unsuspecting world.

All Others Pay Cash is a short film written and starred in by Mickey (and just about everyone else he knows from the look of it)! It's great fun, and there aren't many films where Python nestles so comfortably with chocolate and ridiculousness.

Mickey also has a personal blog (which is mainly about Python).

He has also just launched a new site:

This site is is about the black art of developing integrated software in a project setting. Smile

Like this post? Digg it or it.

Posted by Fuzzyman on 2007-04-28 00:20:09 | |

Categories: , ,

Hosted by Webfaction