Python Programming, news on the Voidspace Python Projects and all things techie.
Silverlight: Python in the Browser
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 .
There are two important aspects, and Microsoft chose to announce them at the same time.
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:
- A dynamic version of VB
The DLR is shipped with the IronPython 2.0 distribution. IronRuby is not yet available , 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...
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 . 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 .
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.
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.
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.
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:
As an illustration, here is the resetboard function from the Wordfind sample:
# clear the previous tiles
# reset to the top-level tree if we already had a word.
CURTREE = WORD_TREE
# 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)
PRESSED = 
TILES = rows
# grab controls we'll interact w/
global PROGRESS, STATUS
PROGRESS = Browser.HtmlPage.Document.GetElementByID("progress")
STATUS = Browser.HtmlPage.Document.GetElementByID("status")
# find all words
global WORDS, FOUND_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.
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...
The worst thing about all of this is that it means I have an extra chapter to write in my book...
|||Actually that's not true any more, but it was when I started writing this entry, and it makes a good beginning.|
|||John Lam has a screencast showing the console in use with all four languages.|
|||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.|
|||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).|
|||The other ones use C# and probably need compiling.|
Finding Your Way With GPS
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
IronPython and the Microsoft Dynamic Language Runtime
Today there is exciting news from the world of Microsoft and IronPython, Jim Hugunin has posted a new blog entry:
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 , 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.
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."
More importantly for Andrzej, Resolver on Rails is one step closer...
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.
|||Currently showing nothing but 'Application Error (Rails)', which is deliciously ironic.|
Exploring Second Life... with Python
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:
|||To circumvent potential licensing issues.|
Found someone who likes Vista...
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 , 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')
|||Which I don't mind, since I know my way around the basics well enough.|
Fun With Python Special Methods
From a discussion on Python-Dev about possible changes to super. Slightly unexpected results when doing daft things with __call__ and __getattribute__.
def __getattribute__(self, name):
if name == '__call__':
return lambda: 'something'
return object.__getattribute__(self, name)
>>> x = X()
Threading in IronPython, Aborting Threads and the Evils of Asynchronous Exceptions
I've posted a new article in the IronPython section.
A discussion of asynchronous exceptions (and aborting threads), and some simple examples of threading in IronPython.
It discusses the evils of asynchronous exceptions, looks at the Thread.Abort method on .NET threads, and illustrates simple threading in IronPython.
What makes a test a unit test?
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  :
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.
|||'Borrowed', from a post on the eXtreme Programming Mailing List.|
Categories: General Programming
PyCon UK and Fun at the London Python Meetup
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  crowd of people, maybe fifteen of us (?), a really fun time. Sean McGrath  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.
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 . That will give us a nice hard deadline (albeit later than I would like) for a public beta...
|||Some really decent folk, living in Northampton these events are about the only time I get to see them though.|
|||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.|
|||Which has Python right at the heart of it in more ways than one...|
Teaching Kids to Program
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.
Python would be a great first language of course, and with its cleaner syntax arguably a better fit than Ruby.
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.
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.
|||It's already in the hands of a few Nigerian schoolchildren.|
All Others Pay Cash: Fun, Ridiculousness and Python
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.
This work is licensed under a Creative Commons Attribution-Share Alike 2.0 License.